-
-
Save luggage66/1aa8125d51f7010ee22d 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
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