CEC-1691 Handle 503 errors (#156)

This commit is contained in:
John Wu
2022-05-18 16:02:13 -07:00
committed by GitHub
parent 8fde694801
commit 23111f9c3a
8 changed files with 206 additions and 104 deletions

View File

@@ -1,13 +1,28 @@
import { logger } from "../services/monitoring";
export const getAuthHeaderOptions = (token) => ({
"Authorization": `Bearer ${token}`,
});
export const addQueryParams = (url, params) => {
if (!params) return url;
const u = new URL(url);
Object.keys(params).forEach((key) => u.searchParams.append(key, params[key]));
return u.toString();
};
export const errorHandler = (e) => {
logger.error(e.stack);
return {
error: e.name,
message: e.message,
};
};
export const fetchRespHandler = (response) => {
if (response.ok) return response.json();
return response.text()
return response
.text()
.then((text) => {
if (response.status >= 500) logger.error(text);
return JSON.parse(text);
@@ -18,15 +33,9 @@ export const fetchRespHandler = (response) => {
error: response.statusText,
message: `${response.status} ${response.statusText}`,
};
})
}
});
};
export const addQueryParams = (url, params) => {
if (!params) return url;
const u = new URL(url);
Object.keys(params).forEach(key => u.searchParams.append(key, params[key]))
return u.toString();
}
export const getAuthHeaderOptions = (token) => ({
Authorization: `Bearer ${token}`,
});