forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.js
More file actions
executable file
·45 lines (37 loc) · 1.07 KB
/
errors.js
File metadata and controls
executable file
·45 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var config = require('config');
var log = require('lib/log')(module);
var HttpError = require('error').HttpError;
module.exports = function(app) {
/* TODO: rewrite this express-style error handling in koa
@see https://github.com/koajs/koa/wiki/Error-Handling
this.use(function(req, res, next) {
next(404);
});
this.use(function(err, req, res, next) {
if (typeof err == 'number') {
err = new HttpError(err);
}
if (err.name == 'CastError') {
// malformed or absent mongoose params
if (process.env.NODE_ENV == 'development') {
log.error(err);
}
res.sendHttpError(new HttpError(400));
return;
}
if (err instanceof HttpError) {
res.sendHttpError(err);
} else {
// if error is "call stack too long", then log.error(err) is not verbose
// so I cast it to string
log.error(err.toString());
if (process.env.NODE_ENV == 'development') {
errorhandler()(err, req, res, next);
} else {
res.sendHttpError(new HttpError(500));
}
}
});
*/
};