Skip to content

Instantly share code, notes, and snippets.

@greyscaled
Last active June 2, 2018 05:32
Show Gist options
  • Save greyscaled/2d69a85b4abd293811f57c83557ef4b6 to your computer and use it in GitHub Desktop.
Save greyscaled/2d69a85b4abd293811f57c83557ef4b6 to your computer and use it in GitHub Desktop.
catch (err) {
// never forget to rollback
await transaction.rollback()
if (err instanceof TypeError) {
// we know now that we couldn't find a team
return res.status(404).send('useful message regarding team not found')
}
else if (err.message === 'tag not found') {
// we know now that we couldn't find one of the tags by supplied id
return res.status(404).send('...')
}
else {
// something else happened (such as db connection, model constraints etc.)
return next(err) // if you're using error handling middleware
// else something like the following:
// console.log(err.stack) // we will want to know what
// res.status(500).send() // send a 500
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment