dl-commons 0.1.1 → 0.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.
|
@@ -6,6 +6,7 @@ declare class HandledException extends HttpException {
|
|
|
6
6
|
private readonly _statusCode?;
|
|
7
7
|
constructor(_errors: RESTError[], _statusCode?: HttpStatus);
|
|
8
8
|
send(response: Response): void;
|
|
9
|
+
private _resolveStatus;
|
|
9
10
|
getErrors(): RESTError[];
|
|
10
11
|
}
|
|
11
12
|
export { HandledException };
|
|
@@ -10,8 +10,13 @@ class HandledException extends common_1.HttpException {
|
|
|
10
10
|
this._statusCode = _statusCode;
|
|
11
11
|
}
|
|
12
12
|
send(response) {
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const status = this._resolveStatus();
|
|
14
|
+
const responseBody = rest_wrapper_class_1.RESTResponseBody.fail(this._errors, status);
|
|
15
|
+
response.status(status).json(responseBody);
|
|
16
|
+
}
|
|
17
|
+
_resolveStatus() {
|
|
18
|
+
const candidate = Number(this._statusCode);
|
|
19
|
+
return Number.isInteger(candidate) && candidate >= 100 && candidate <= 999 ? candidate : common_1.HttpStatus.BAD_REQUEST;
|
|
15
20
|
}
|
|
16
21
|
getErrors() {
|
|
17
22
|
return this._errors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.exception.js","sourceRoot":"","sources":["../../src/exceptions/custom.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAE3D,mFAAyF;AAEzF,MAAM,gBAAiB,SAAQ,sBAAa;IACxC,YAA6B,OAAoB,EAAmB,WAAwB;QACxF,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,WAAW,IAAI,mBAAU,CAAC,WAAW,CAAC,CAAC;QADzC,YAAO,GAAP,OAAO,CAAa;QAAmB,gBAAW,GAAX,WAAW,CAAa;IAE5F,CAAC;IAEM,IAAI,CAAC,QAAkB;
|
|
1
|
+
{"version":3,"file":"custom.exception.js","sourceRoot":"","sources":["../../src/exceptions/custom.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAE3D,mFAAyF;AAEzF,MAAM,gBAAiB,SAAQ,sBAAa;IACxC,YAA6B,OAAoB,EAAmB,WAAwB;QACxF,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,WAAW,IAAI,mBAAU,CAAC,WAAW,CAAC,CAAC;QADzC,YAAO,GAAP,OAAO,CAAa;QAAmB,gBAAW,GAAX,WAAW,CAAa;IAE5F,CAAC;IAEM,IAAI,CAAC,QAAkB;QAU1B,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,MAAM,YAAY,GAAG,qCAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACjE,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAEO,cAAc;QAClB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3C,OAAO,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAU,CAAC,WAAW,CAAC;IACpH,CAAC;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAEQ,4CAAgB"}
|
|
@@ -4,10 +4,18 @@ exports.validationExceptionFactory = validationExceptionFactory;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const custom_exception_1 = require("../exceptions/custom.exception");
|
|
6
6
|
const rest_wrapper_class_1 = require("../models/dtos/wrappers/rest-wrapper.class");
|
|
7
|
+
function sanitize(error) {
|
|
8
|
+
var _a;
|
|
9
|
+
return {
|
|
10
|
+
property: error.property,
|
|
11
|
+
constraints: error.constraints,
|
|
12
|
+
children: ((_a = error.children) === null || _a === void 0 ? void 0 : _a.length) ? error.children.map(sanitize) : error.children,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
7
15
|
function validationExceptionFactory(_errors) {
|
|
8
16
|
const error = new rest_wrapper_class_1.RESTError('data_validation');
|
|
9
17
|
_errors.forEach((i) => {
|
|
10
|
-
error.validation = i;
|
|
18
|
+
error.validation = sanitize(i);
|
|
11
19
|
});
|
|
12
20
|
return new custom_exception_1.HandledException([error], common_1.HttpStatus.UNPROCESSABLE_ENTITY);
|
|
13
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.factory.js","sourceRoot":"","sources":["../../src/factories/exception.factory.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"exception.factory.js","sourceRoot":"","sources":["../../src/factories/exception.factory.ts"],"names":[],"mappings":";;AA+BS,gEAA0B;AA/BnC,2CAA4C;AAE5C,qEAAkE;AAClE,mFAAuE;AAQvE,SAAS,QAAQ,CAAC,KAAsB;;IACpC,OAAO;QACH,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,QAAQ,EAAE,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,EAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ;KACnF,CAAC;AACN,CAAC;AAED,SAAS,0BAA0B,CAAC,OAA0B;IAC1D,MAAM,KAAK,GAAG,IAAI,8BAAS,CAAC,iBAAiB,CAAC,CAAC;IAK/C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAClB,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,mCAAgB,CAAC,CAAC,KAAK,CAAC,EAAE,mBAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dl-commons",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "distance learning commons",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
|
-
],
|
|
10
|
+
],
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=20.19.0"
|
|
13
13
|
},
|
|
@@ -46,17 +46,18 @@
|
|
|
46
46
|
"@nestjs/mongoose": "^10.1.0",
|
|
47
47
|
"@types/express": "^4.17.25",
|
|
48
48
|
"@types/node": "^20.19.43",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
50
|
-
"@typescript-eslint/parser": "^6.21.0",
|
|
51
49
|
"axios": "^1.7.2",
|
|
52
50
|
"bson": "^6.10.4",
|
|
53
51
|
"class-transformer": "^0.5.1",
|
|
54
52
|
"class-validator": "^0.14.4",
|
|
55
|
-
"eslint": "^8.
|
|
53
|
+
"eslint": "^10.8.0",
|
|
54
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
56
55
|
"express": "^4.18.2",
|
|
56
|
+
"globals": "^17.9.0",
|
|
57
57
|
"mongoose": "^8.24.2",
|
|
58
58
|
"reflect-metadata": "^0.2.2",
|
|
59
59
|
"rxjs": "^7.8.1",
|
|
60
|
-
"typescript": "^5.9.3"
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"typescript-eslint": "^8.66.0"
|
|
61
62
|
}
|
|
62
63
|
}
|