mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -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()
|
var app = express()
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
function error_reporting_middleware(req, res, next) {
|
||||||
var calls = 0
|
var calls = 0
|
||||||
res.report_error = function(err) {
|
res.report_error = res.report_error || function(err) {
|
||||||
calls++
|
calls++
|
||||||
if (err.status && err.status >= 400 && err.status < 600) {
|
if (err.status && err.status >= 400 && err.status < 600) {
|
||||||
if (calls == 1) {
|
if (calls == 1) {
|
||||||
|
@ -56,8 +56,9 @@ module.exports = function(config_hash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
})
|
}
|
||||||
|
|
||||||
|
app.use(error_reporting_middleware)
|
||||||
app.use(Middleware.log_and_etagify)
|
app.use(Middleware.log_and_etagify)
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
res.setHeader('X-Powered-By', 'Sinopia')
|
res.setHeader('X-Powered-By', 'Sinopia')
|
||||||
|
@ -285,6 +286,11 @@ module.exports = function(config_hash) {
|
||||||
|
|
||||||
app.use(app.router)
|
app.use(app.router)
|
||||||
app.use(function(err, req, res, next) {
|
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)
|
res.report_error(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue