Skip to content

Instantly share code, notes, and snippets.

@lubien
Created January 23, 2018 00:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lubien/0a0d3db958be208eb2e769349b89fe77 to your computer and use it in GitHub Desktop.
const databaseGetUser = id =>
id === 'not-exists'
? Promise.reject('some weird database error')
: Promise.resolve({id, username: 'username'})
function getUser(id) {
return databaseGetUser(id)
.catch(err => { throw 'user doesn\'t exists' })
}
getUser('lubien').then(console.log) // works fine
getUser('not-exists').catch(console.error) // 'user doesn't exists'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment