Skip to content

Instantly share code, notes, and snippets.

@ziedHamdi
Created August 5, 2022 13:15
Show Gist options
  • Save ziedHamdi/09d7556b3cc06e07e47a71321d5046a5 to your computer and use it in GitHub Desktop.
Save ziedHamdi/09d7556b3cc06e07e47a71321d5046a5 to your computer and use it in GitHub Desktop.
class ExtendableError extends Error {
constructor(message, errorCode) {
super(JSON.stringify( {text:message, code:errorCode} ))
this.name = this.constructor.name;
// this.errorCode = errorCode
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error(message)).stack;
}
}
}
export default ExtendableError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment