diff --git a/src/common/util/RequestUtil.js b/src/common/util/RequestUtil.js index 945c520..27df997 100644 --- a/src/common/util/RequestUtil.js +++ b/src/common/util/RequestUtil.js @@ -9,11 +9,18 @@ export const request = async (path, method = "GET", body = {}, headers = {}, abo if (abort) setTimeout(() => {controller.abort()}, 10000); - return await fetch("/api" + path, { + const result = await fetch("/api" + path, { headers: {"Content-Type": "application/json", ...getHeaders(), ...headers}, method, body: method !== "GET" ? JSON.stringify(body) : null, signal: controller.signal }); + + if (result.status === 401) { + localStorage.removeItem("token"); + throw new Error("Unauthorized"); + } + + return result; } // Run a GET request and get the json of the response