-
-
Save girvo/9e7bad4974480085ea13 to your computer and use it in GitHub Desktop.
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
// TypedError class which other typed errors subclass from. | |
class TypedError extends Error { | |
constructor (message) { | |
super(); | |
if (Error.hasOwnProperty('captureStackTrace')) | |
Error.captureStackTrace(this, this.constructor); | |
else | |
Object.defineProperty(this, 'stack', { | |
value: (new Error()).stack | |
}); | |
Object.defineProperty(this, 'message', { | |
value: message | |
}); | |
} | |
get name () { | |
return this.constructor.name; | |
} | |
} | |
export class NotFoundError extends TypedError {} | |
export class MethodError extends TypedError {} | |
export class NotAcceptableError extends TypedError {} | |
export class UnsupportedError extends TypedError {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment