Last active
July 5, 2019 21:09
-
-
Save amiratak88/745de4b831685a3beab5eacc2306c751 to your computer and use it in GitHub Desktop.
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
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