feat(logging): improve logging removing not useful data and distinguishing between user and server errors

This commit is contained in:
Matteo Pagliazzi
2016-05-26 23:10:38 +02:00
parent b03985c6b2
commit c6192dd24b
2 changed files with 32 additions and 8 deletions

View File

@@ -12,12 +12,6 @@ import {
} from 'lodash';
module.exports = function errorHandler (err, req, res, next) { // eslint-disable-line no-unused-vars
logger.error(err, {
originalUrl: req.originalUrl,
headers: omit(req.headers, ['x-api-key']),
body: req.body,
});
// In case of a CustomError class, use it's data
// Otherwise try to identify the type of error (mongoose validation, mongodb unique, ...)
// If we can't identify it, respond with a generic 500 error
@@ -70,6 +64,14 @@ module.exports = function errorHandler (err, req, res, next) { // eslint-disable
responseErr = new InternalServerError();
}
// log the error
logger.error(err, {
originalUrl: req.originalUrl,
headers: omit(req.headers, ['x-api-key', 'cookie']), // don't send sensitive information that only adds noise
body: req.body,
statusCode: responseErr.httpCode,
});
let jsonRes = {
success: false,
error: responseErr.name,