Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions app/src/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,14 @@ function errorHandler(err: unknown, _req: NextRequest) {
{ status: 400 },
);
} else if (err instanceof OpenAI.APIError) {
const { name, status, headers, message } = err;
return NextResponse.json({ name, status, headers, message }, { status });
const { name, status, message } = err;
return NextResponse.json(
{ error: { name, message } },
{ status: status ?? 500 },
);
} else {
let errorMessage = "Unknown error";
if ((err as Object).hasOwnProperty("message")) {
errorMessage = (err as Error).message;
} else if (err instanceof Error) {
errorMessage = (err as Object).toString();
}
return NextResponse.json(
{ error: { message: "Internal server error", error: errorMessage } },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea here of not accidentally leaking database details (hoewever all of our DB structure etc. is available publicly in this repository), for now I would hold off on merging this though.
This information can be crucial for debugging and until we have Grafana fully set up on our prod environment we kind of rely on this to debug it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemilonkh nice! Do we have on our roadmap when we plan to have Grafana fully set up or is it something being discussed yet?

{ error: { message: "Internal server error" } },
{ status: 500 },
);
}
Expand Down
Loading