diff --git a/lib/cartodb/middleware/error-middleware.js b/lib/cartodb/middleware/error-middleware.js index 80457b9c..f372648d 100644 --- a/lib/cartodb/middleware/error-middleware.js +++ b/lib/cartodb/middleware/error-middleware.js @@ -18,7 +18,8 @@ module.exports = function errorMiddleware (/* options */) { if (err.message === 'Tile does not exist' && res.locals.format === 'mvt') { statusCode = 204; } - + + logErrors(allErrors, statusCode, res); debug('[%s ERROR] -- %d: %s, %s', label, statusCode, err, err.stack); // If a callback was requested, force status to 200 @@ -31,6 +32,7 @@ module.exports = function errorMiddleware (/* options */) { errors_with_context: allErrors.map(errorMessageWithContext) }; + res.status(statusCode); if (req.query && req.query.callback) { @@ -160,3 +162,36 @@ function errorMessageWithContext(err) { return error; } + +function logErrors(errors, statusCode, res) { + console.log(' -----------------------------') + console.log('logErrors'); + console.log(' -----------------------------') + + if(!errors || !errors.length || !statusCode) { + return; + } + + const mainError = errors.shift(); + + const errorsLog = { + statusCode, + message: mainError.message, + type: mainError.type, + subtype: mainError.subtype + } + + errorsLog.moreErrors = errors.map(error => { + return { + message: error.message, + type: error.type, + subtype: error.subtype + }; + }); + + console.log(' -----------------------------') + console.log(errorsLog) + console.log(' -----------------------------') + + res.set('X-Tiler-Errors', JSON.stringify(errorsLog)); +} \ No newline at end of file