Skip to content

Instantly share code, notes, and snippets.

@csymlstd
Created November 16, 2018 15:37
Show Gist options
  • Save csymlstd/bfdb73549bec6202b744fcbd30f52557 to your computer and use it in GitHub Desktop.
Save csymlstd/bfdb73549bec6202b744fcbd30f52557 to your computer and use it in GitHub Desktop.
Custom Error class
// https://levelup.gitconnected.com/the-definite-guide-to-handling-errors-gracefully-in-javascript-58424d9c60e6
class CustomError extends Error {
constructor(code = 'GENERIC', status = 500, ...params) {
super(...params)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, CustomError)
}
this.code = code
this.status = status
}
}
module.exports = CustomError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment