adding error name, ensuring data and moving errors copy
This commit is contained in:
parent
f24217a400
commit
667925c455
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user