Skip to content

Commit

Permalink
add try catch and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
GAllen98 committed Feb 6, 2025
1 parent 8ef9ddc commit 4e6b0c0
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/services/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,31 @@ export async function startUIServer(
});

app.get("/api/history", async (req, res) => {
const { searchParams } = new URL(req.url);
const id = searchParams.get("id");
const url = `${apiConfig.url}/history?id=${id}`;
try {
console.log("GET /api/history");

const response = await fetch(url, {
headers: {
Authorization: `Bearer ${apiConfig.key}`,
},
});
const id = req.query.id;
if (!id) {
throw new Error("No history id on request.");
}
const url = `${apiConfig.url}/history?id=${id}`;

console.log(url);
console.log(apiConfig.key);

const response = await fetch(url, {
headers: {
Authorization: `Bearer ${apiConfig.key}`,
},
});

const result = await response.json();
console.log(result);

const result = await response.json();
res.json(result);
res.json(result);
} catch (err) {
res.status(500).json({ error: `Failed to fetch chat history: ${err}` });
}
});

// Serve index.html for all routes
Expand Down

0 comments on commit 4e6b0c0

Please sign in to comment.