Skip to content

Commit

Permalink
Show error dialog for 500 featch responses
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Nov 6, 2023
1 parent 5d20f94 commit 0c2097f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions frontend/src/hooks.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

0 comments on commit 0c2097f

Please sign in to comment.