| 28 | let endpoint = `${apiUrl}:${apiPort}/chatapi/v1/chats/${current_chatTapID}/chatlogs`; |
| 29 | |
| 30 | async function fetchData(endpoint, method, body = null) { |
| 31 | const options = { |
| 32 | method: method, |
| 33 | headers: { |
| 34 | "Content-Type": "application/json", |
| 35 | }, |
| 36 | }; |
| 37 | |
| 38 | if (body) { |
| 39 | options.body = JSON.stringify(body); |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | const response = await fetch(endpoint, options); |
| 44 | const data = await response.json(); |
| 45 | return data; |
| 46 | } catch (err) { |
| 47 | console.error(`Error in fetchData for ${endpoint}:`, err); |
| 48 | throw err; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | let data = await fetchData(endpoint, "GET"); |
| 53 | return data; |