adding errors to errors header
This commit is contained in:
parent
e362fca9eb
commit
84fd01535c
@ -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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user