正在显示
2 个修改的文件
包含
17 行增加
和
9 行删除
1 | 1 | |
2 | 2 | // # boot - error handler |
3 | 3 | |
4 | +var mergeDefaults = require('merge-defaults') | |
4 | 5 | var _ = require('underscore') |
5 | 6 | var util = require('util') |
6 | 7 | |
... | ... | @@ -67,13 +68,6 @@ exports = module.exports = function(logger, settings) { |
67 | 68 | |
68 | 69 | // set error level |
69 | 70 | var level = (res.statusCode < 500) ? 'warn' : 'error' |
70 | - logger[level](error) | |
71 | - | |
72 | - // set error back to warning if it was warn | |
73 | - // logger level type = "warn" | |
74 | - // req.flash messages type = "warning" | |
75 | - if (level === 'warn') | |
76 | - level = 'warning' | |
77 | 71 | |
78 | 72 | // if we have a mongoose validation err |
79 | 73 | // then we know to output all the errors |
... | ... | @@ -92,7 +86,10 @@ exports = module.exports = function(logger, settings) { |
92 | 86 | res.send(error.message) |
93 | 87 | }, |
94 | 88 | html: function() { |
95 | - req.flash(level, error.message) | |
89 | + // set error back to warning if it was warn | |
90 | + // logger level type = "warn" | |
91 | + // req.flash messages type = "warning" | |
92 | + req.flash(level === 'warn' ? 'warning' : level, error.message) | |
96 | 93 | res.redirect('back') |
97 | 94 | }, |
98 | 95 | json: function() { |
... | ... | @@ -100,6 +97,17 @@ exports = module.exports = function(logger, settings) { |
100 | 97 | } |
101 | 98 | }) |
102 | 99 | |
100 | + if (_.isObject(req.log)) { | |
101 | + req.log.response_time = new Date().getTime() - req.log.response_time | |
102 | + req.log.status = res.statusCode | |
103 | + req.log.response_type = res.get('Content-Type') | |
104 | + req.log.response_body = error | |
105 | + } else { | |
106 | + req.log = error | |
107 | + } | |
108 | + | |
109 | + logger[level](req.log) | |
110 | + | |
103 | 111 | }) |
104 | 112 | |
105 | 113 | } | ... | ... |
请
注册
或
登录
后发表评论