CEC-279 Add logger (#62)
* CEC-279 Add logger * Error log 500 status requests
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { logger } from "../services/monitoring";
|
||||
|
||||
export const getAuthHeaderOptions = (token) => ({
|
||||
"Authorization": `Bearer ${token}`,
|
||||
});
|
||||
@@ -6,11 +8,17 @@ export const fetchRespHandler = (response) => {
|
||||
if (response.ok) return response.json();
|
||||
|
||||
return response.text()
|
||||
.then((text) => JSON.parse(text))
|
||||
.catch((e) => ({
|
||||
error: response.statusText,
|
||||
message: `${response.status} ${response.statusText}`,
|
||||
}))
|
||||
.then((text) => {
|
||||
if (response.status >= 500) logger.error(text);
|
||||
return JSON.parse(text);
|
||||
})
|
||||
.catch((e) => {
|
||||
logger.error(e.stack);
|
||||
return {
|
||||
error: response.statusText,
|
||||
message: `${response.status} ${response.statusText}`,
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
export const addQueryParams = (url, params) => {
|
||||
|
||||
Reference in New Issue
Block a user