isvalid 4.1.2 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/validate.js +16 -8
- package/package.json +1 -1
- package/test/validate.js +1 -1
package/lib/validate.js
CHANGED
|
@@ -76,12 +76,16 @@ const validateObject = async (data, schema, options, keyPath, validatedData) =>
|
|
|
76
76
|
}
|
|
77
77
|
} catch (error) {
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
switch (options.aggregatedErrors || 'none') {
|
|
80
|
+
case 'none': throw error;
|
|
81
|
+
case 'flatten':
|
|
82
|
+
errors = errors.concat(error.errors || [error]);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
errors.push(error);
|
|
86
|
+
break;
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
errors.push(error);
|
|
84
|
-
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
}
|
|
@@ -134,12 +138,16 @@ const validateArray = async (data, schema, options, keyPath, validatedData) => {
|
|
|
134
138
|
data[idx] = await validateAny(data[idx], schema.schema, options, keyPath.concat([idx]), validatedData);
|
|
135
139
|
} catch (error) {
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
switch (options.aggregatedErrors || 'none') {
|
|
142
|
+
case 'none': throw error;
|
|
143
|
+
case 'flatten':
|
|
144
|
+
errors = errors.concat(error.errors || [error]);
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
errors.push(error);
|
|
148
|
+
break;
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
errors.push(error);
|
|
142
|
-
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
153
|
|
package/package.json
CHANGED
package/test/validate.js
CHANGED
|
@@ -488,7 +488,7 @@ describe('validate', function() {
|
|
|
488
488
|
type: String,
|
|
489
489
|
required: true
|
|
490
490
|
}
|
|
491
|
-
}}, { keyPath: ['root'],
|
|
491
|
+
}}, { keyPath: ['root'], aggregatedErrors: true }))
|
|
492
492
|
.to.eventually.be.rejectedWith('Multiple errors occurred.')
|
|
493
493
|
.and.to.be.instanceOf(AggregatedError)
|
|
494
494
|
.and.have.property('errors')
|