Improve error processing with syncpipe
This commit is contained in:
parent
4af5f1f001
commit
9a31868883
|
@ -3,6 +3,7 @@
|
|||
const isArguments = require("is-arguments");
|
||||
const flatten = require("flatten");
|
||||
const asExpression = require("as-expression");
|
||||
const syncpipe = require("syncpipe");
|
||||
|
||||
const ValidationError = require("@validatem/error");
|
||||
const annotateErrors = require("@validatem/annotate-errors");
|
||||
|
@ -63,15 +64,12 @@ function applyDefinitions(args, definitions, remainingArgumentsIndex) {
|
|||
};
|
||||
});
|
||||
|
||||
// FIXME: Investigate syncpipe usage here
|
||||
let combinedErrors = results.map((result) => result.errors);
|
||||
let flattenedErrors = flatten(combinedErrors); // TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021)
|
||||
|
||||
let newValues = results.map((result) => result.newValue);
|
||||
|
||||
return {
|
||||
errors: flattenedErrors,
|
||||
newValue: newValues
|
||||
errors: syncpipe(results, [
|
||||
(_) => _.map((result) => result.errors),
|
||||
(_) => flatten(_) // TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021)
|
||||
]),
|
||||
newValue: results.map((result) => result.newValue)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue