Add message for when unauthorised

This commit is contained in:
Fred Boniface 2024-07-03 11:00:50 +01:00
parent fddf9cbbaf
commit 5a9e55c695

View File

@ -34,8 +34,12 @@ export async function apiGet(path: string): Promise<any> {
try { try {
const res = await fetch(getUrlString() + path, options); const res = await fetch(getUrlString() + path, options);
if (res.status === 401) {
throw new Error("Registration not accepted. Register at `Menu > Registration`");
}
if (!res.ok) { 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"); const contentType = res.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) { if (!contentType || !contentType.includes("application/json")) {