Created
April 19, 2021 12:20
-
-
Save malte-j/fbd66d5373653779531655f611cbf2f7 to your computer and use it in GitHub Desktop.
JS Custom Error with error code
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
class ApplicationError extends Error { | |
constructor(errorCode, ...params) { | |
// Pass remaining arguments (including vendor specific ones) to parent constructor | |
super(...params); | |
// Maintains proper stack trace for where our error was thrown (only available on V8) | |
if (Error.captureStackTrace) { | |
Error.captureStackTrace(this, ApplicationError) | |
} | |
this.name = 'ApplicationError'; | |
// Custom debugging information | |
this.errorCode = errorCode; | |
this.date = new Date(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment