Skip to content

Commit da01a11

Browse files
committed
Improve validation error messages
1 parent 8344f9f commit da01a11

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/routeGeneration/templateHelpers.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export class ValidationService {
384384

385385
if (!subFieldErrors.some(subFieldError => Object.keys(subFieldError).length === 0)) {
386386
fieldErrors[parent + name] = {
387-
message: `Could not match the union against any of the items. Issues: ${subFieldErrors}`,
387+
message: `Could not match the union against any of the items. Issues: ${JSON.stringify(subFieldErrors)}`,
388388
value,
389389
};
390390
return;
@@ -420,16 +420,18 @@ export class ValidationService {
420420
});
421421

422422
subFieldErrors.forEach(subFieldError => {
423-
(Object as any).entries(subFieldError).forEach(([key, value]) => {
423+
Object.entries(subFieldError).forEach(([key, value]) => {
424424
if (value.message.includes('excess')) {
425425
delete subFieldError[key];
426426
}
427427
});
428428
});
429429

430-
if (subFieldErrors.some(subFieldError => Object.keys(subFieldError).length !== 0)) {
430+
const filtered = subFieldErrors.filter(subFieldError => Object.keys(subFieldError).length !== 0);
431+
432+
if (filtered.length > 0) {
431433
fieldErrors[parent + name] = {
432-
message: `Could not match the intersection against every type. Issues: ${subFieldErrors}`,
434+
message: `Could not match the intersection against every type. Issues: ${JSON.stringify(filtered)}`,
433435
value,
434436
};
435437
return;
@@ -571,6 +573,7 @@ export class ValidationService {
571573

572574
return value;
573575
}
576+
}
574577

575578
export interface IntegerValidator {
576579
isInt?: { errorMsg?: string };

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"target": "es5",
88
"lib": [
99
"es6",
10+
"es2017.object",
1011
"dom"
1112
],
1213
"typeRoots": [

0 commit comments

Comments
 (0)