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 }));