Compare commits

...

2 Commits

@ -47,18 +47,23 @@ module.exports = function wrapError(message, rules, options = {}) {
if (!preserveOriginalErrors) { if (!preserveOriginalErrors) {
return [ new ValidationError(message) ]; return [ new ValidationError(message) ];
} else { } else {
let newRootErrors = (hasRootValidationErrors) // If possible, we try to move any subpath errors into the subErrors of an (optionally newly-created) root error. Otherwise, it can become difficult for the user to correlate together the root and subpath errors that are related, when we start changing the messages of the root errors.
? errorsByType.validationRoot.map((error) => { if (errorsByType.validationRoot.length === 0) {
// TODO: Currently we cannot set `originalError` due to a bug in `create-error`; switch to a better error implementation return [ new ValidationError(message, { subErrors: errorsByType.validationPath }) ];
// return new ValidationError(`${message} (${error.message})`, { originalError: error }) } else if (errorsByType.validationRoot.length === 1) {
return new ValidationError(`${message} (${error.message})`) let error = errorsByType.validationRoot[0];
})
: [ new ValidationError(message) ]; // TODO: Currently we cannot set `originalError` due to a bug in `create-error`; switch to a better error implementation
return [ new ValidationError(`${message} (${error.message})`, { subErrors: errorsByType.validationPath }) ];
return concat([ } else {
newRootErrors, // If there are multiple root errors, we cannot determine which root error the subpath errors belong to, so we'll just provide them as a flat list
errorsByType.validationPath return concat([
]); errorsByType.validationRoot.map((error) => {
return new ValidationError(`${message} (${error.message})`)
}),
errorsByType.validationPath
]);
}
} }
} else { } else {
return []; return [];

@ -6,7 +6,7 @@
"validator", "validator",
"combinator" "combinator"
], ],
"version": "0.1.2", "version": "0.1.3",
"main": "index.js", "main": "index.js",
"repository": "http://git.cryto.net/validatem/wrap-error.git", "repository": "http://git.cryto.net/validatem/wrap-error.git",
"author": "Sven Slootweg <admin@cryto.net>", "author": "Sven Slootweg <admin@cryto.net>",

Loading…
Cancel
Save