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