Skip to content

Instantly share code, notes, and snippets.

@embarq
Created June 3, 2017 02:06
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save embarq/56a5d04a8a42f2a282dc9b5d68bb2d43 to your computer and use it in GitHub Desktop.
Save embarq/56a5d04a8a42f2a282dc9b5d68bb2d43 to your computer and use it in GitHub Desktop.
Custom errors in TypeScript
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);
}
}
@rommelsanthiago
Copy link

Thank you very much, this helped me a lot today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment