Integrated error handling into the RequestUtil.js
This commit is contained in:
parent
4bd0e1b72b
commit
0b93f024ec
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user