Skip to content

Instantly share code, notes, and snippets.

@amiratak88
Last active July 5, 2019 21:09
Show Gist options
  • Save amiratak88/745de4b831685a3beab5eacc2306c751 to your computer and use it in GitHub Desktop.
Save amiratak88/745de4b831685a3beab5eacc2306c751 to your computer and use it in GitHub Desktop.
function makefetchCall() {
fetch('...', {...})
.then(res => {
if (!res.ok) {
throw Error({ message: 'Response with error', code: res.status })
}
return res.json()
})
.then(json => {
console.log(json)
})
.catch(e => {
if (e.code) {
// Means you got a response with error status code
} else {
// There was no response due to invalid url or no internet connection or ......
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment