@nathapp/nestjs-common 2.0.3 → 2.1.0
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.
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DefaultI18nValidationExceptionFilter = exports.defaultResponseFormatter = void 0;
|
|
4
4
|
const i18n_validation_exception_filter_1 = require("./i18n-validation-exception.filter");
|
|
5
5
|
const _1 = require(".");
|
|
6
|
+
const findFirstError = (error) => {
|
|
7
|
+
if (error.children && error.children.length > 0) {
|
|
8
|
+
return findFirstError(error.children[0]);
|
|
9
|
+
}
|
|
10
|
+
return error;
|
|
11
|
+
};
|
|
6
12
|
const defaultResponseFormatter = (hostname, exc, formattedErrors) => {
|
|
7
13
|
if (!Array.isArray(formattedErrors)) {
|
|
8
14
|
throw new _1.AppException(-2);
|
|
@@ -16,11 +22,13 @@ const defaultResponseFormatter = (hostname, exc, formattedErrors) => {
|
|
|
16
22
|
}
|
|
17
23
|
return error;
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
const firstError = findFirstError(error);
|
|
26
|
+
if (firstError) {
|
|
27
|
+
message = firstError.constraints[Object.keys(firstError.constraints)[0]];
|
|
28
|
+
errors[firstError.property] = Object.keys(firstError.constraints).map((key) => {
|
|
29
|
+
return firstError.constraints[key];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
24
32
|
});
|
|
25
33
|
return {
|
|
26
34
|
ret: -2,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-i18n-validation-exception.filter.js","sourceRoot":"","sources":["../../lib/exception/default-i18n-validation-exception.filter.ts"],"names":[],"mappings":";;;AAKA,yFAG4C;AAE5C,wBAAiC;
|
|
1
|
+
{"version":3,"file":"default-i18n-validation-exception.filter.js","sourceRoot":"","sources":["../../lib/exception/default-i18n-validation-exception.filter.ts"],"names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