Skip to content

Instantly share code, notes, and snippets.

@malte-j
Created April 19, 2021 12:20
Show Gist options
  • Save malte-j/fbd66d5373653779531655f611cbf2f7 to your computer and use it in GitHub Desktop.
Save malte-j/fbd66d5373653779531655f611cbf2f7 to your computer and use it in GitHub Desktop.
JS Custom Error with error code
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