Make sure all errors use the serializer set for the logger

This commit is contained in:
Daniel García Aubert 2020-06-03 17:32:16 +02:00
parent 1dda183a31
commit 210f5b01ec
10 changed files with 19 additions and 10 deletions

View File

@ -342,7 +342,8 @@ function incrementMapViews ({ metadataBackend }) {
mapConfigProvider.getMapConfig((err, mapConfig) => {
if (err) {
logger.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
err.message = `Failed to increment mapview count for user '${user}'. ${err.message}`;
logger.warn({ error: err });
return next();
}
@ -354,7 +355,8 @@ function incrementMapViews ({ metadataBackend }) {
metadataBackend.incMapviewCount(user, statTag, (err) => {
if (err) {
logger.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
err.message = `Failed to increment mapview count for user '${user}'. ${err.message}`;
logger.warn({ error: err });
}
next();

View File

@ -10,7 +10,8 @@ module.exports = function setCacheChannelHeader () {
mapConfigProvider.getAffectedTables((err, affectedTables) => {
if (err) {
logger.warn(err, 'ERROR generating Cache Channel Header');
err.message = `Error generating Cache Channel Header. ${err.message}`;
logger.warn({ error: err });
return next();
}

View File

@ -44,7 +44,8 @@ module.exports = function setCacheControlHeader ({
mapConfigProvider.getAffectedTables((err, affectedTables) => {
if (err) {
logger.warn(err, 'ERROR generating Cache Control Header');
err.message = `Error generating Cache Control Header. ${err.message}`;
logger.warn({ error: err });
return next();
}

View File

@ -5,7 +5,7 @@ module.exports = function errorMiddleware (/* options */) {
const { logger } = res.locals;
const errors = populateLimitErrors(Array.isArray(err) ? err : [err]);
logger.error({ errors });
logger.error({ error: errors });
const errorResponseBody = {
errors: errors.map(errorMessage),

View File

@ -14,7 +14,8 @@ module.exports = function incrementMapViewCount (metadataBackend) {
req.profiler.done('incMapviewCount');
if (err) {
logger.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
err.message = `Failed to increment mapview count for user '${user}'. ${err.message}`;
logger.warn({ error: err });
}
next();

View File

@ -21,7 +21,8 @@ module.exports = function setLastModifiedHeader () {
mapConfigProvider.getAffectedTables((err, affectedTables) => {
if (err) {
logger.warn(err, 'ERROR generating Last Modified Header');
err.message = `Error generating Last Modified Header. ${err.message}`;
logger.warn({ error: err });
return next();
}

View File

@ -15,6 +15,8 @@ module.exports = function metrics ({ enabled, tags, metricsBackend }) {
}
return function metricsMiddleware (req, res, next) {
// FIXME: use parent logger as we don't want bind the error to the request
// but we still want to know if an error is thrown
const { logger } = res.locals;
res.on('finish', () => {

View File

@ -17,7 +17,8 @@ module.exports = function setSurrogateKeyHeader ({ surrogateKeysCache }) {
mapConfigProvider.getAffectedTables((err, affectedTables) => {
if (err) {
logger.warn(err, 'ERROR generating Surrogate Key Header');
err.message = `Erros generating Surrogate Key Header. ${err.message}`;
logger.warn({ error: err });
return next();
}

View File

@ -13,7 +13,7 @@ module.exports = class Logger {
serializers: {
request: requestSerializer,
response: responseSerializer,
errors: (errors) => errors.map((err) => errorSerializer(err))
error: (error) => Array.isArray(error) ? error.map((err) => errorSerializer(err)) : [errorSerializer(error)]
}
};
const dest = pino.destination({ sync: false }); // stdout

View File

@ -67,7 +67,7 @@ describe('turbo-carto regressions', function () {
});
});
it('should fail for private tables', function (done) {
it.only('should fail for private tables', function (done) {
var cartocss = [
'#private_table {',
' marker-placement: point;',