Skip to content

Instantly share code, notes, and snippets.

@uwuru
uwuru / fetch-better-error-handling.js
Created July 20, 2019 20:30
Javascript fetch with better error handling example
return fetch(url)
.then((response) => {
if (response.ok) {
return response.json()
}
throw response
})
.catch((error) => {
if (error instanceof Error) {
return { error }