fix(collection-confirm): log server errors and return generic message to client

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
SJCoetz 2026-08-03 00:59:02 +02:00
parent bb10f1350b
commit e860611980
2 changed files with 10 additions and 6 deletions

View file

@ -29,12 +29,18 @@ describe("GET /api/v1/collection-confirm", () => {
await expect(response.json()).resolves.toEqual(rows);
});
it("returns a 500 with an error body when the service throws", async () => {
it("returns a 500 with a generic error body and logs the original error", async () => {
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
vi.mocked(listCollectedItems).mockRejectedValue(new Error("PB down"));
const response = await GET();
expect(response.status).toBe(500);
await expect(response.json()).resolves.toEqual({ error: "PB down" });
await expect(response.json()).resolves.toEqual({ error: "internal error" });
expect(errorSpy).toHaveBeenCalledWith(
"[GET /api/v1/collection-confirm]",
expect.any(Error),
);
errorSpy.mockRestore();
});
});

View file

@ -6,9 +6,7 @@ export async function GET(): Promise<NextResponse> {
const rows = await listCollectedItems();
return NextResponse.json(rows);
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "internal error" },
{ status: 500 },
);
console.error("[GET /api/v1/collection-confirm]", error);
return NextResponse.json({ error: "internal error" }, { status: 500 });
}
}