diff --git a/lib/cartodb/middleware/error-middleware.js b/lib/cartodb/middleware/error-middleware.js index 6e45f1da..9246ca7f 100644 --- a/lib/cartodb/middleware/error-middleware.js +++ b/lib/cartodb/middleware/error-middleware.js @@ -187,7 +187,7 @@ function setErrorHeader(errors, statusCode, res) { }; }); - res.set('X-Tiler-Errors', JSON.stringify(errorsLog)); + res.set('X-Tiler-Errors', stringifyForLogs(errorsLog)); } /** @@ -198,13 +198,16 @@ function setErrorHeader(errors, statusCode, res) { */ function stringifyForLogs(object) { Object.keys(object).map(key => { - const value = object[key]; - if (object instanceof Object) { - stringifyForLogs(value); - } else { + if (typeof object[key] === 'object') { + stringifyForLogs(object[key]); + } else if (object[key] instanceof Array) { + for (let element of object[key]) { + stringifyForLogs(element); + } + } else if(typeof object[key] === 'string') { object[key] = object[key].replace(/[^a-zA-Z0-9]/g, ' '); } }); return JSON.stringify(object); -} \ No newline at end of file +} \ No newline at end of file