Skip to content

Instantly share code, notes, and snippets.

@luggage66
Created May 22, 2015 17:21
Show Gist options
  • Save luggage66/1aa8125d51f7010ee22d to your computer and use it in GitHub Desktop.
Save luggage66/1aa8125d51f7010ee22d to your computer and use it in GitHub Desktop.
import _ from 'lodash';
class TypedError extends Error
{
constructor(message) {
super();
this.stack = new Error().stack;
this.message = this.constructor.name + ': ' + message;
this.status = 500;
}
}
export class InvalidOperationError extends TypedError {
constructor(message) {
super(message);
this.status = 400;
}
}
export class RoutingError extends TypedError {
constructor(message) {
super(message);
this.status = 404;
}
}
export class ValidationError extends TypedError {
constructor(errors) {
super('Validation Failed');
this.status = 400;
this.validationErrors = errors;
}
static fromCheckitError(err) {
var errors = _.map(err.errors, (v, k) => { return { field: k, message: v.message };});
return new this(errors);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment