From 893c192b94ded098e264ac216fb1c82ef0f5baca Mon Sep 17 00:00:00 2001 From: Sverre Blekastad Stensby Date: Mon, 11 Nov 2024 12:30:52 +0100 Subject: [PATCH] Viser bedre feilmeldinger fra 404-requests. --- client/src/api/lydia-api/networkRequests.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/src/api/lydia-api/networkRequests.ts b/client/src/api/lydia-api/networkRequests.ts index 7e310befe..3ecba87ce 100644 --- a/client/src/api/lydia-api/networkRequests.ts +++ b/client/src/api/lydia-api/networkRequests.ts @@ -56,7 +56,21 @@ const fetchNative = }, }), ) - .then((res) => (res.ok ? res : Promise.reject(res.text()))) + .then((res) => { + if (res.ok) { + return res; + } + + if (res.status === 404) { + return Promise.reject( + Promise.resolve( + `Noe gikk galt. Fant ikke ressursen: ${url}`, + ), + ); + } + + return Promise.reject(res.text()); + }) .then((res) => res.json()) .catch((e: Promise) => { e.then((reason) => {