add option to errorHandler to skip logging

This commit is contained in:
Phillip Thelen
2025-08-04 17:40:26 +02:00
parent 1ee172139d
commit 7c49b845d6
2 changed files with 19 additions and 13 deletions

View File

@@ -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();

View File

@@ -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,