Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Marcellin committed May 16, 2024
2 parents 812bf43 + fde6c63 commit d2de58e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ const prepareRequest = (init: any, token?: string) => {
}
const initCopy = Object.assign({}, init);
initCopy.headers = new Headers(initCopy.headers || {});
initCopy.headers.append(
'Authorization',
'Bearer ' + (token ?? getUserToken())
);
const tokenCopy = token ?? getUserToken();
initCopy.headers.append('Authorization', 'Bearer ' + tokenCopy);
return initCopy;
};

Expand All @@ -44,29 +42,31 @@ const handleError = (response: any) => {
return response.text().then((text: string) => {
const errorName = 'HttpResponseError : ';
const errorJson = parseError(text);
let customError: { message?: string; status?: string } = {};
let customError: Error & { status?: string };
if (
errorJson &&
errorJson.status &&
errorJson.error &&
errorJson.message
) {
customError.message =
customError = new Error(
errorName +
errorJson.status +
' ' +
errorJson.error +
', message : ' +
errorJson.message;
errorJson.status +
' ' +
errorJson.error +
', message : ' +
errorJson.message
);
customError.status = errorJson.status;
} else {
customError.message =
customError = new Error(
errorName +
response.status +
' ' +
response.statusText +
', message : ' +
text;
response.status +
' ' +
response.statusText +
', message : ' +
text
);
customError.status = response.status;
}
throw customError;
Expand Down

0 comments on commit d2de58e

Please sign in to comment.