Created
November 16, 2016 15:25
-
-
Save awerlang/a0abdbc102220e92f16a3479e1ce894e to your computer and use it in GitHub Desktop.
Sample implementation of a custom error
This file contains hidden or 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 CustomError extends Error { | |
get name(): string { return 'CustomError'; }; | |
public stack: any; | |
constructor(public code: number, public message: string) { | |
super(message); | |
if (typeof (<any>Error).captureStackTrace === 'function') { | |
(<any>Error).captureStackTrace(this, this.constructor); | |
} else { | |
this.stack = (<any>(new Error())).stack; | |
} | |
} | |
toString() { | |
return this.name + '[' + this.code + ']: ' + this.message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment