MCPcopy Create free account
hub / github.com/OpenSIST/OpenSIST.github.io / handleErrors

Function handleErrors

src/Data/Common.js:40–67  ·  view source on GitHub ↗
(response, {allowUnauthorized = false} = {})

Source from the content-addressed store, hash-verified

38}
39
40export async function handleErrors(response, {allowUnauthorized = false} = {}) {
41 /*
42 * Handle the error of the response
43 * @param response [Response]: response from fetch
44 * @return: response
45 */
46 if (response.status === 401) {
47 await emptyCache();
48 if (allowUnauthorized) {
49 return response;
50 }
51 if (!["/agreement", "/login", "/register", "/reset"].includes(window.location.pathname)) {
52 window.location.assign("/login");
53 }
54 throw new Response('', {
55 status: response.status,
56 statusText: response.statusText,
57 });
58 }
59 if (!response.ok) {
60 const content = await response.json().catch(() => ({}));
61 throw new Response('', {
62 status: response.status,
63 statusText: content.error ?? response.statusText,
64 });
65 }
66 return response;
67}
68
69export function blobToBase64(blob) {
70 return new Promise((resolve, reject) => {

Callers 1

apiRequestFunction · 0.85

Calls 1

emptyCacheFunction · 0.85

Tested by

no test coverage detected