UNPKG

841 BJavaScriptView Raw
1var util = require('util')
2
3var AppError = function (msg, constr) {
4 if(msg) {
5 msg = msg.toString();
6 }
7 Error.captureStackTrace(this, constr || this)
8 this.message = msg || 'Error'
9 this.name = 'AppError'
10 this.status = 200
11}
12util.inherits(AppError, Error)
13
14var NotFoundError = function(msg) {
15 NotFoundError.super_.call(this, msg, this.constructor)
16 this.message = msg || 'Not Found';
17 this.name = 'NotFoundError'
18 this.status = 404
19}
20util.inherits(NotFoundError, AppError)
21
22var UnauthorizedError = function(msg) {
23 UnauthorizedError.super_.call(this, msg, this.constructor)
24 this.message = msg || `401 Unauthorized`;
25 this.name = 'UnauthorizedError'
26 this.status = 401
27}
28util.inherits(UnauthorizedError, AppError)
29
30module.exports = {
31 AppError: AppError,
32 NotFound: NotFoundError,
33 Unauthorized: UnauthorizedError
34}
35