Created
November 16, 2018 15:37
-
-
Save csymlstd/bfdb73549bec6202b744fcbd30f52557 to your computer and use it in GitHub Desktop.
Custom Error class
This file contains 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
// 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