adding error name, ensuring data and moving errors copy

This commit is contained in:
Simon Martín 2017-11-27 16:43:04 +01:00
parent f24217a400
commit 667925c455

View File

@ -15,11 +15,12 @@ module.exports = function errorMiddleware (/* options */) {
var statusCode = findStatusCode(err);
logErrors(allErrors, statusCode, res);
if (err.message === 'Tile does not exist' && res.locals.format === 'mvt') {
statusCode = 204;
}
logErrors(Object.assign({}, allErrors), statusCode, res);
debug('[%s ERROR] -- %d: %s, %s', label, statusCode, err, err.stack);
// If a callback was requested, force status to 200
@ -164,22 +165,26 @@ function errorMessageWithContext(err) {
}
function logErrors(errors, statusCode, res) {
if(!errors || !errors.length || !statusCode) {
const errorsCopy = Object.assign({}, errors);
if(!errorsCopy || !errorsCopy.length) {
return;
}
const mainError = errors.shift();
const mainError = errorsCopy.shift();
const errorsLog = {
statusCode,
statusCode: statusCode || 200,
message: mainError.message,
name: mainError.name,
type: mainError.type,
subtype: mainError.subtype
};
errorsLog.moreErrors = errors.map(error => {
errorsLog.moreErrors = errorsCopy.map(error => {
return {
message: error.message,
name: error.name,
type: error.type,
subtype: error.subtype
};