Created
May 12, 2021 07:48
-
-
Save younho9/9d94afe35eeba2d54a455d0e72df5dc1 to your computer and use it in GitHub Desktop.
Fetch Error Handling
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 handleErrors = (res: Response) => { | |
if (!res.ok) { | |
throw Error(res.statusText); | |
} | |
return res; | |
} | |
fetch("http://httpstat.us/500") | |
.then(handleErrors) | |
.then((res) => res.json()) | |
.catch((err) => console.log(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment