From 3581af2bf91d9138b862d2783a3a3b20cabf1a63 Mon Sep 17 00:00:00 2001 From: Marcel Raddatz Date: Fri, 3 Apr 2026 09:25:06 +0200 Subject: [PATCH] fix(staples): forward backend error status code instead of always 500 Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/routes/household/staples/+server.ts | 3 ++- frontend/src/routes/household/staples/server.test.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/household/staples/+server.ts b/frontend/src/routes/household/staples/+server.ts index c22cb44..11ac42f 100644 --- a/frontend/src/routes/household/staples/+server.ts +++ b/frontend/src/routes/household/staples/+server.ts @@ -21,7 +21,8 @@ export const PATCH: RequestHandler = async ({ request, fetch }) => { }); if (error) { - return json({ error: 'Failed to update ingredient' }, { status: 500 }); + const status = (error as { status?: number }).status ?? 500; + return json({ error: 'Failed to update ingredient' }, { status }); } return new Response(null, { status: 204 }); diff --git a/frontend/src/routes/household/staples/server.test.ts b/frontend/src/routes/household/staples/server.test.ts index 81418dc..10b3c04 100644 --- a/frontend/src/routes/household/staples/server.test.ts +++ b/frontend/src/routes/household/staples/server.test.ts @@ -46,7 +46,7 @@ describe('household staples PATCH handler', () => { expect(response.status).toBe(204); }); - it('returns 500 when backend returns an error', async () => { + it('returns 500 when backend returns a 500 error', async () => { mockPatch.mockResolvedValue({ data: undefined, error: { status: 500, message: 'error' } }); const response = await PATCH(createRequest({ id: 'ing-1', isStaple: false })); @@ -54,6 +54,14 @@ describe('household staples PATCH handler', () => { expect(response.status).toBe(500); }); + it('forwards backend 404 status when ingredient not found', async () => { + mockPatch.mockResolvedValue({ data: undefined, error: { status: 404 } }); + + const response = await PATCH(createRequest({ id: 'ing-1', isStaple: false })); + + expect(response.status).toBe(404); + }); + it('returns 400 when id is missing', async () => { const response = await PATCH(createRequest({ isStaple: true }));