mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
add option to errorHandler to skip logging
This commit is contained in:
@@ -53,12 +53,16 @@ export default function ipBlocker (req, res, next) {
|
||||
|
||||
const ipMatch = blockedIps.find(blockedIp => blockedIp === req.ip) !== undefined;
|
||||
if (ipMatch === true) {
|
||||
return next(new Forbidden(apiError('ipAddressBlocked')));
|
||||
const error = new Forbidden(apiError('ipAddressBlocked'));
|
||||
error.skipLogging = true;
|
||||
return next(error);
|
||||
}
|
||||
|
||||
const clientMatch = blockedClients.find(blockedClient => blockedClient === req.headers['x-client']) !== undefined;
|
||||
if (clientMatch === true) {
|
||||
return next(new Forbidden(apiError('clientBlocked')));
|
||||
const error = new Forbidden(apiError('clientBlocked'));
|
||||
error.skipLogging = true;
|
||||
return next(error);
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
@@ -66,19 +66,21 @@ export default function errorHandler (err, req, res, next) { // eslint-disable-l
|
||||
responseErr = new InternalServerError();
|
||||
}
|
||||
|
||||
// log the error
|
||||
logger.error(err, {
|
||||
method: req.method,
|
||||
originalUrl: req.originalUrl,
|
||||
if (!err.skipLogging) {
|
||||
// log the error
|
||||
logger.error(err, {
|
||||
method: req.method,
|
||||
originalUrl: req.originalUrl,
|
||||
|
||||
// don't send sensitive information that only adds noise
|
||||
headers: omit(req.headers, ['x-api-key', 'cookie', 'password', 'confirmPassword']),
|
||||
body: omit(req.body, ['password', 'confirmPassword']),
|
||||
query: omit(req.query, ['password', 'confirmPassword']),
|
||||
// don't send sensitive information that only adds noise
|
||||
headers: omit(req.headers, ['x-api-key', 'cookie', 'password', 'confirmPassword']),
|
||||
body: omit(req.body, ['password', 'confirmPassword']),
|
||||
query: omit(req.query, ['password', 'confirmPassword']),
|
||||
|
||||
httpCode: responseErr.httpCode,
|
||||
isHandledError: responseErr.httpCode < 500,
|
||||
});
|
||||
httpCode: responseErr.httpCode,
|
||||
isHandledError: responseErr.httpCode < 500,
|
||||
});
|
||||
}
|
||||
|
||||
const jsonRes = {
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user