Created
June 3, 2017 02:06
-
-
Save embarq/56a5d04a8a42f2a282dc9b5d68bb2d43 to your computer and use it in GitHub Desktop.
Custom errors in TypeScript
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
import ExpressValidator = require('express-validator'); | |
export class HttpError extends Error { | |
constructor(public code: number, message: string) { | |
super(message); | |
Object.setPrototypeOf(this, HttpError.prototype); | |
} | |
} | |
export class RequestValidationError extends Error { | |
public readonly name: 'RequestValidationError'; | |
constructor(public error: ExpressValidator.Dictionary<ExpressValidator.MappedError>) { | |
super(); | |
Object.setPrototypeOf(this, RequestValidationError.prototype); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much, this helped me a lot today