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