diff --git a/src/app/api/v1/collection-confirm/route.test.ts b/src/app/api/v1/collection-confirm/route.test.ts index ec6dd4d..84b2d38 100644 --- a/src/app/api/v1/collection-confirm/route.test.ts +++ b/src/app/api/v1/collection-confirm/route.test.ts @@ -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(); }); }); diff --git a/src/app/api/v1/collection-confirm/route.ts b/src/app/api/v1/collection-confirm/route.ts index 0ad5b91..b0b726c 100644 --- a/src/app/api/v1/collection-confirm/route.ts +++ b/src/app/api/v1/collection-confirm/route.ts @@ -6,9 +6,7 @@ export async function GET(): Promise { 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 }); } }