adding errors to errors header

This commit is contained in:
Simon Martín 2017-11-24 17:53:07 +01:00
parent e362fca9eb
commit 84fd01535c

View File

@ -19,6 +19,7 @@ module.exports = function errorMiddleware (/* options */) {
statusCode = 204; statusCode = 204;
} }
logErrors(allErrors, statusCode, res);
debug('[%s ERROR] -- %d: %s, %s', label, statusCode, err, err.stack); debug('[%s ERROR] -- %d: %s, %s', label, statusCode, err, err.stack);
// If a callback was requested, force status to 200 // If a callback was requested, force status to 200
@ -31,6 +32,7 @@ module.exports = function errorMiddleware (/* options */) {
errors_with_context: allErrors.map(errorMessageWithContext) errors_with_context: allErrors.map(errorMessageWithContext)
}; };
res.status(statusCode); res.status(statusCode);
if (req.query && req.query.callback) { if (req.query && req.query.callback) {
@ -160,3 +162,36 @@ function errorMessageWithContext(err) {
return error; 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));
}