mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
feat(logging): improve logging removing not useful data and distinguishing between user and server errors
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user