Last active
May 10, 2020 21:41
-
-
Save ThomasAribart/59250a539532011a27fd594a7ddd56d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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