fix copying array of errors and adding error.label to logs

This commit is contained in:
Simon Martín 2017-11-27 18:12:44 +01:00
parent 60e4defa66
commit 605d7057c9

View File

@ -163,18 +163,19 @@ function errorMessageWithContext(err) {
} }
function logErrors(errors, statusCode, res) { function logErrors(errors, statusCode, res) {
const errorsCopy = Object.assign({}, errors); const errorsCopy = errors.slice(0);
if(!errorsCopy || !errorsCopy.length) { if(!errorsCopy || !errorsCopy.length) {
return; return;
} }
const mainError = errorsCopy.shift(); const mainError = errorsCopy.shift();
const errorsLog = { const errorsLog = {
statusCode: statusCode || 200, statusCode: statusCode || 200,
message: mainError.message, message: mainError.message,
name: mainError.name, name: mainError.name,
label: mainError.label,
type: mainError.type, type: mainError.type,
subtype: mainError.subtype subtype: mainError.subtype
}; };
@ -183,10 +184,11 @@ function logErrors(errors, statusCode, res) {
return { return {
message: error.message, message: error.message,
name: error.name, name: error.name,
label: error.label,
type: error.type, type: error.type,
subtype: error.subtype subtype: error.subtype
}; };
}); });
res.set('X-Tiler-Errors', JSON.stringify(errorsLog)); res.set('X-Tiler-Errors', JSON.stringify(errorsLog));
} }