From cbad650abc49bf2d05635abd2ed56e3a98022fe7 Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Tue, 31 Oct 2023 11:34:47 +0100 Subject: [PATCH] Show error dialog for 500 featch responses --- frontend/src/hooks.client.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frontend/src/hooks.client.ts b/frontend/src/hooks.client.ts index 5160b2bd3..30e638bd0 100644 --- a/frontend/src/hooks.client.ts +++ b/frontend/src/hooks.client.ts @@ -63,11 +63,18 @@ function shouldTryAutoReload(updateDetected: boolean): boolean { */ handleFetch(async ({ fetch, args }) => { const response = await traceFetch(() => fetch(...args)); + if (response.status === 401 && location.pathname !== '/login') { throw redirect(307, '/logout'); } + + if (response.status >= 500) { + throw new Error(`Unexpected response: ${response.statusText} (${response.status}). URL: ${response.url}.`); + } + if (response.headers.get('lexbox-refresh-jwt') == 'true') { await invalidate(USER_LOAD_KEY); } + return response; });