Created
March 15, 2021 18:14
-
-
Save awmpietro/474f256b4b86861daa3f7be435c84e61 to your computer and use it in GitHub Desktop.
Simple error message handler if you use Axios
This file contains hidden or 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 errorHandler = (error) => { | |
| if (error.response) { | |
| // error message returned from axios request | |
| return error.response.data; | |
| } else { | |
| // default error message | |
| return error.message; | |
| } | |
| }; | |
| export default errorHandler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment