Skip to content

Instantly share code, notes, and snippets.

@Gaafar
Last active May 19, 2019 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gaafar/96b0112ffc18a44fc2c2019cc3b960d3 to your computer and use it in GitHub Desktop.
Save Gaafar/96b0112ffc18a44fc2c2019cc3b960d3 to your computer and use it in GitHub Desktop.
.catch with sync error
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