0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

logging caused failure in case of errors

This commit is contained in:
Alex Kocharin 2013-10-11 09:46:37 +04:00
parent 9ee525b317
commit 3596a12eb7

View file

@ -58,35 +58,41 @@ Storage.prototype.request = function(options, cb) {
body: json,
ca: this.ca,
}, function(err, res, body) {
var res_length = body.length;
if (options.json) {
try {
body = JSON.parse(body);
} catch(err) {
return cb(err);
if (!err) {
var res_length = body.length;
if (options.json) {
try {
body = JSON.parse(body);
} catch(err) {
return cb(err);
}
}
if (typeof(body) === 'object' && body !== null) {
if (body.error) {
var error = body.error;
}
}
} else {
var error = err.message;
}
if (typeof(body) === 'object' && body != null) {
if (body.error) {
var error = body.error;
}
}
var msg = '@{status}, req: \'@{request.method} @{request.url}\'';
var msg = '@{!status}, req: \'@{request.method} @{request.url}\'';
if (error) {
msg += ', error: @{!error}';
} else {
msg += ', bytes: @{bytes.in}/@{bytes.out}';
}
self.logger.warn({
err: err,
request: {method: method, url: uri},
level: 35, // http
status: res.statusCode,
status: res != null ? res.statusCode : 'ERR',
error: error,
bytes: {
in: json ? json.length : 0,
out: res_length,
out: res_length || 0,
}
}, msg);
if (cb) cb.apply(self, arguments);