Skip to content

Instantly share code, notes, and snippets.

@ThomasAribart
Last active May 10, 2020 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasAribart/59250a539532011a27fd594a7ddd56d3 to your computer and use it in GitHub Desktop.
Save ThomasAribart/59250a539532011a27fd594a7ddd56d3 to your computer and use it in GitHub Desktop.
const parseStatusCode = (originalStatusCode) => {
switch (true) {
case defaultStatusCodes.has(originalStatusCode):
return originalStatusCode;
case originalStatusCode < 500:
return 400;
default:
return 500;
}
};
export const axiosErrorParser = {
detect: error => error.isAxiosError,
parse: error =>
new CustomError(parseStatusCode(error.response.status), {
key: 'AXIOS_ERROR',
message: error.message,
}),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment