1 | var util = require('util')
|
2 |
|
3 | var 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 | }
|
12 | util.inherits(AppError, Error)
|
13 |
|
14 | var 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 | }
|
20 | util.inherits(NotFoundError, AppError)
|
21 |
|
22 | var 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 | }
|
28 | util.inherits(UnauthorizedError, AppError)
|
29 |
|
30 | module.exports = {
|
31 | AppError: AppError,
|
32 | NotFound: NotFoundError,
|
33 | Unauthorized: UnauthorizedError
|
34 | }
|
35 |
|