Skip to content

Instantly share code, notes, and snippets.

@younho9
Created May 12, 2021 07:48
Show Gist options
  • Save younho9/9d94afe35eeba2d54a455d0e72df5dc1 to your computer and use it in GitHub Desktop.
Save younho9/9d94afe35eeba2d54a455d0e72df5dc1 to your computer and use it in GitHub Desktop.
Fetch Error Handling
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