mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-20 22:52:46 -05:00
dealing with express.js errors
This commit is contained in:
parent
75e78b4137
commit
7b0ab14d4c
1 changed files with 9 additions and 3 deletions
12
lib/index.js
12
lib/index.js
|
@ -38,9 +38,9 @@ module.exports = function(config_hash) {
|
|||
|
||||
var app = express()
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
function error_reporting_middleware(req, res, next) {
|
||||
var calls = 0
|
||||
res.report_error = function(err) {
|
||||
res.report_error = res.report_error || function(err) {
|
||||
calls++
|
||||
if (err.status && err.status >= 400 && err.status < 600) {
|
||||
if (calls == 1) {
|
||||
|
@ -56,8 +56,9 @@ module.exports = function(config_hash) {
|
|||
}
|
||||
}
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
||||
app.use(error_reporting_middleware)
|
||||
app.use(Middleware.log_and_etagify)
|
||||
app.use(function(req, res, next) {
|
||||
res.setHeader('X-Powered-By', 'Sinopia')
|
||||
|
@ -285,6 +286,11 @@ module.exports = function(config_hash) {
|
|||
|
||||
app.use(app.router)
|
||||
app.use(function(err, req, res, next) {
|
||||
if (typeof(res.report_error) !== 'function') {
|
||||
// in case of very early error this middleware may not be loaded before error is generated
|
||||
// fixing that
|
||||
error_reporting_middleware(req, res, function(){})
|
||||
}
|
||||
res.report_error(err)
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue