diff --git a/lib/api/map/preview-template-controller.js b/lib/api/map/preview-template-controller.js index 92d4380e..49ee18c7 100644 --- a/lib/api/map/preview-template-controller.js +++ b/lib/api/map/preview-template-controller.js @@ -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(); diff --git a/lib/api/middlewares/cache-channel-header.js b/lib/api/middlewares/cache-channel-header.js index 66486392..622aa053 100644 --- a/lib/api/middlewares/cache-channel-header.js +++ b/lib/api/middlewares/cache-channel-header.js @@ -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(); } diff --git a/lib/api/middlewares/cache-control-header.js b/lib/api/middlewares/cache-control-header.js index 18ec7728..5ae0d481 100644 --- a/lib/api/middlewares/cache-control-header.js +++ b/lib/api/middlewares/cache-control-header.js @@ -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(); } diff --git a/lib/api/middlewares/error-middleware.js b/lib/api/middlewares/error-middleware.js index 645a8992..faca863f 100644 --- a/lib/api/middlewares/error-middleware.js +++ b/lib/api/middlewares/error-middleware.js @@ -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), diff --git a/lib/api/middlewares/increment-map-view-count.js b/lib/api/middlewares/increment-map-view-count.js index 1b71e8e3..ea4fc285 100644 --- a/lib/api/middlewares/increment-map-view-count.js +++ b/lib/api/middlewares/increment-map-view-count.js @@ -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(); diff --git a/lib/api/middlewares/last-modified-header.js b/lib/api/middlewares/last-modified-header.js index b68d7c31..f2d41292 100644 --- a/lib/api/middlewares/last-modified-header.js +++ b/lib/api/middlewares/last-modified-header.js @@ -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(); } diff --git a/lib/api/middlewares/metrics.js b/lib/api/middlewares/metrics.js index dc69b373..6b7a9ff8 100644 --- a/lib/api/middlewares/metrics.js +++ b/lib/api/middlewares/metrics.js @@ -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', () => { diff --git a/lib/api/middlewares/surrogate-key-header.js b/lib/api/middlewares/surrogate-key-header.js index c1415038..c8fd550d 100644 --- a/lib/api/middlewares/surrogate-key-header.js +++ b/lib/api/middlewares/surrogate-key-header.js @@ -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(); } diff --git a/lib/utils/logger.js b/lib/utils/logger.js index 0a4b3df0..54beee2e 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -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 diff --git a/test/acceptance/turbo-carto/regressions-test.js b/test/acceptance/turbo-carto/regressions-test.js index e36dc2e1..d0ba7d89 100644 --- a/test/acceptance/turbo-carto/regressions-test.js +++ b/test/acceptance/turbo-carto/regressions-test.js @@ -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;',