Created
November 30, 2016 14:43
-
-
Save jaredpalmer/1a185f5c724510d648b81fcdffdcdf85 to your computer and use it in GitHub Desktop.
errors
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
'use strict' | |
const uuid = require('node-uuid') | |
class APIError extends Error { | |
constructor (opts) { | |
super(opts) | |
Error.captureStackTrace(this, APIError) | |
this.name = this.constructor.name || 'APIError' | |
this.code = opts.code || 500 | |
this.level = opts.level || 'normal' | |
this.id = uuid.v4() | |
} | |
} | |
class NotFoundError extends APIError { | |
constructor (message = 'Not found', code = 404) { | |
super(message, code) | |
} | |
} | |
class ForbiddenError extends APIError { | |
constructor (message = 'Forbidden', code = 403) { | |
super(message, code) | |
} | |
} | |
class UnauthorizedError extends APIError { | |
constructor (message = 'Unauthorized', code = 401) { | |
super(message, code) | |
} | |
} | |
class BadRequestError extends APIError { | |
constructor (message = 'Bad request data', code = 400, fields = {}) { | |
super(message, code) | |
this.fields = fields | |
} | |
} | |
module.exports = { | |
APIError, | |
UnauthorizedError, | |
NotFoundError, | |
ForbiddenError, | |
BadRequestError | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment