Skip to content

Commit

Permalink
Return warning level to debug on expected http status codes 401, 404.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Dec 12, 2023
1 parent 1dfa516 commit c749941
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,22 @@ class HttpClient {
throw newError;
}

const status = error.response && error.response.status;
let level = 'warn';
let message = 'HttpClient Response Error';
if (!error) {
message = 'HttpClient Response Error - Unknown error occurred';
} else if (error.response && error.response.status === 401) {
} else if (status === 401) {
message = 'HttpClient Response Error due to invalid token';
level = 'debug';
} else if (status === 404) {
message = 'HttpClient Response: Not Found';
level = 'debug';
}

this.logger.warn({ title: message, online: navigator.onLine, method, url, data, headers, error, resolvedError });
if (this.logger[level]) {
this.logger[level]({ title: message, online: navigator.onLine, method, url, status, data, headers, error, resolvedError });
}
throw error;
}
}
Expand Down

0 comments on commit c749941

Please sign in to comment.