Last active
May 19, 2019 09:01
-
-
Save Gaafar/96b0112ffc18a44fc2c2019cc3b960d3 to your computer and use it in GitHub Desktop.
.catch with sync error
This file contains hidden or 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 getJSON = () => { | |
// here url is not defined and will throw an error | |
// since the error is thrown before returning the promise, | |
// it won't be caught by .catch | |
console.log(url) | |
return Promise.resolve() | |
} | |
const makeRequest = () => getJSON() | |
.then(JSON.parse) | |
.then(console.log) | |
.catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment