From 5a9e55c695382f344fd2ddbf26ecf563ea5d464c Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 3 Jul 2024 11:00:50 +0100 Subject: [PATCH] Add message for when unauthorised --- src/lib/scripts/apiFetch.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/scripts/apiFetch.ts b/src/lib/scripts/apiFetch.ts index ba9ce53..972d077 100644 --- a/src/lib/scripts/apiFetch.ts +++ b/src/lib/scripts/apiFetch.ts @@ -34,8 +34,12 @@ export async function apiGet(path: string): Promise { try { const res = await fetch(getUrlString() + path, options); + if (res.status === 401) { + throw new Error("Registration not accepted. Register at `Menu > Registration`"); + } + if (!res.ok) { - throw new Error("Network response not ok"); + throw new Error(`Failed: ${res.status}: ${res.statusText}`); } const contentType = res.headers.get("content-type"); if (!contentType || !contentType.includes("application/json")) {