fiscalia_bo-nest-helpers 0.1.14 → 0.1.15
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/dist/helpers/global-exception.filter.d.ts +4 -1
- package/dist/helpers/global-exception.filter.js +47 -3
- package/dist/helpers/global-exception.filter.js.map +1 -1
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/package.json +4 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ExceptionFilter, ArgumentsHost, BadRequestException, HttpException, NotAcceptableException } from '@nestjs/common';
|
1
|
+
import { ExceptionFilter, ArgumentsHost, BadRequestException, HttpException, NotAcceptableException, UnauthorizedException } from '@nestjs/common';
|
2
2
|
export declare class GlobalExceptionFilter implements ExceptionFilter {
|
3
3
|
catch(error: Error, host: ArgumentsHost): void;
|
4
4
|
}
|
@@ -11,3 +11,6 @@ export declare class ApiBadRequestError extends BadRequestException {
|
|
11
11
|
export declare class NotAcceptableError extends NotAcceptableException {
|
12
12
|
constructor(message?: string, status?: number, response?: any, error?: boolean);
|
13
13
|
}
|
14
|
+
export declare class ApiUnauthorizedError extends UnauthorizedException {
|
15
|
+
constructor(message?: string, response?: any, status?: number, error?: boolean);
|
16
|
+
}
|
@@ -6,8 +6,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
7
|
};
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
-
exports.NotAcceptableError = exports.ApiBadRequestError = exports.MsSeguridadHttpError = exports.GlobalExceptionFilter = void 0;
|
9
|
+
exports.ApiUnauthorizedError = exports.NotAcceptableError = exports.ApiBadRequestError = exports.MsSeguridadHttpError = exports.GlobalExceptionFilter = void 0;
|
10
10
|
const common_1 = require("@nestjs/common");
|
11
|
+
const throttler_1 = require("@nestjs/throttler");
|
11
12
|
let GlobalExceptionFilter = class GlobalExceptionFilter {
|
12
13
|
catch(error, host) {
|
13
14
|
const response = host.switchToHttp().getResponse();
|
@@ -25,6 +26,10 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
25
26
|
resp.message = 'No encontrado';
|
26
27
|
resp.status = 404;
|
27
28
|
}
|
29
|
+
else if (error instanceof throttler_1.ThrottlerException) {
|
30
|
+
resp.message = 'cantidad de peticiones excedidas';
|
31
|
+
resp.status = 429;
|
32
|
+
}
|
28
33
|
else if (error instanceof common_1.UnprocessableEntityException) {
|
29
34
|
resp.message = 'Entidad no processable';
|
30
35
|
resp.status = 422;
|
@@ -40,6 +45,39 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
40
45
|
if (!resp.status || resp.status < 200)
|
41
46
|
resp.status = 400;
|
42
47
|
}
|
48
|
+
else if (error instanceof MsSeguridadHttpError) {
|
49
|
+
const respErr = error.getResponse();
|
50
|
+
if (typeof (respErr === null || respErr === void 0 ? void 0 : respErr.error) !== 'boolean' && typeof (respErr === null || respErr === void 0 ? void 0 : respErr.message) !== 'string') {
|
51
|
+
if (typeof respErr === 'string')
|
52
|
+
response.message = respErr;
|
53
|
+
}
|
54
|
+
else
|
55
|
+
resp = respErr;
|
56
|
+
if (!resp.status || resp.status < 200)
|
57
|
+
resp.status = 400;
|
58
|
+
}
|
59
|
+
else if (error instanceof Error) {
|
60
|
+
const grpcParsingError = error;
|
61
|
+
if (grpcParsingError.code === 14 &&
|
62
|
+
grpcParsingError.details.includes('No connection established')) {
|
63
|
+
resp.message = 'Error al conectarse al servicio de GRPC';
|
64
|
+
resp.status = 422;
|
65
|
+
}
|
66
|
+
else if (grpcParsingError.code === 13 &&
|
67
|
+
grpcParsingError.details.includes('Response message parsing error:')) {
|
68
|
+
resp.message = 'Error al convertir las respuestas de GRPC';
|
69
|
+
resp.status = 422;
|
70
|
+
}
|
71
|
+
else if (grpcParsingError.code === 12 &&
|
72
|
+
grpcParsingError.details.includes('[object Object]')) {
|
73
|
+
resp.message =
|
74
|
+
'Error: el micro servicio de GRPC no tiene implementado este método o esta ignorado en MS-MYSQL.';
|
75
|
+
resp.status = 422;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
if (resp.status === 500 && resp.message === 'Error interno del servidor') {
|
79
|
+
console.error(error);
|
80
|
+
}
|
43
81
|
response.status(resp.status).json(resp);
|
44
82
|
}
|
45
83
|
};
|
@@ -48,13 +86,13 @@ GlobalExceptionFilter = __decorate([
|
|
48
86
|
], GlobalExceptionFilter);
|
49
87
|
exports.GlobalExceptionFilter = GlobalExceptionFilter;
|
50
88
|
class MsSeguridadHttpError extends common_1.HttpException {
|
51
|
-
constructor(message = '
|
89
|
+
constructor(message = 'Ocurrió un error', status = 400, response = null, error = true) {
|
52
90
|
super({ error, message, status, response }, status);
|
53
91
|
}
|
54
92
|
}
|
55
93
|
exports.MsSeguridadHttpError = MsSeguridadHttpError;
|
56
94
|
class ApiBadRequestError extends common_1.BadRequestException {
|
57
|
-
constructor(message = '
|
95
|
+
constructor(message = 'Ocurrió un error', status = 400, response = null, error = true) {
|
58
96
|
super({ error, message, status, response });
|
59
97
|
}
|
60
98
|
}
|
@@ -65,4 +103,10 @@ class NotAcceptableError extends common_1.NotAcceptableException {
|
|
65
103
|
}
|
66
104
|
}
|
67
105
|
exports.NotAcceptableError = NotAcceptableError;
|
106
|
+
class ApiUnauthorizedError extends common_1.UnauthorizedException {
|
107
|
+
constructor(message = 'usuario no autenticado y/o token no válido', response = null, status = 401, error = true) {
|
108
|
+
super({ error, message, status, response });
|
109
|
+
}
|
110
|
+
}
|
111
|
+
exports.ApiUnauthorizedError = ApiUnauthorizedError;
|
68
112
|
//# sourceMappingURL=global-exception.filter.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"global-exception.filter.js","sourceRoot":"","sources":["../../src/helpers/global-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
1
|
+
{"version":3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;QAEZ,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF;AATD,gDASC;AAKD,MAAa,oBAAqB,SAAQ,8BAAqB;IAC7D,YACE,OAAO,GAAG,4CAA4C,EACtD,QAAQ,GAAG,IAAI,EACf,MAAM,GAAG,GAAG,EACZ,KAAK,GAAG,IAAI;QAEZ,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF;AATD,oDASC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PackageJson = exports.Exceptions = void 0;
|
4
|
+
exports.Exceptions = require("./global-exception.filter");
|
5
|
+
exports.PackageJson = require("./package-json.helper");
|
6
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,0DAAwD;AACxD,uDAAqD"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.RequestRestrict = exports.Dtos = exports.Decorators = exports.CustomValidators = exports.MsSkylogs = exports.MsFiles = exports.MsPdf = exports.MsPersonas = exports.PermissionsGuard = exports.MsSeguridadHttpError = void 0;
|
17
|
+
exports.Helpers = exports.RequestRestrict = exports.Dtos = exports.Decorators = exports.CustomValidators = exports.MsSkylogs = exports.MsFiles = exports.MsPdf = exports.MsPersonas = exports.PermissionsGuard = exports.MsSeguridadHttpError = void 0;
|
18
18
|
__exportStar(require("./ms-redis/ms-redis.module"), exports);
|
19
19
|
__exportStar(require("./ms-redis/ms-redis.service"), exports);
|
20
20
|
__exportStar(require("./ms-redis/datapass.interceptor"), exports);
|
@@ -40,4 +40,5 @@ exports.CustomValidators = require("./custom-validators");
|
|
40
40
|
exports.Decorators = require("./decorators");
|
41
41
|
exports.Dtos = require("./dto");
|
42
42
|
exports.RequestRestrict = require("./request-restrict");
|
43
|
+
exports.Helpers = require("./helpers");
|
43
44
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "fiscalia_bo-nest-helpers",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.15",
|
4
4
|
"author": "UTIC",
|
5
5
|
"contact": {
|
6
6
|
"name": "Unidad de Tecnologías de la Información y Comunicación - Ministerio Público",
|
@@ -23,6 +23,7 @@
|
|
23
23
|
"dist/helpers/*",
|
24
24
|
"dist/request-restrict/*",
|
25
25
|
"dist/types/*",
|
26
|
+
"dist/helpers/*",
|
26
27
|
"dist/index.d.ts",
|
27
28
|
"*.md"
|
28
29
|
],
|
@@ -58,6 +59,7 @@
|
|
58
59
|
"@grpc/grpc-js": "^1.8.14",
|
59
60
|
"@nestjs/axios": "^2.0.0",
|
60
61
|
"@nestjs/microservices": "^9.3.12",
|
62
|
+
"@nestjs/throttler": "^4.0.0",
|
61
63
|
"axios": "^1.3.4",
|
62
64
|
"class-transformer": "^0.5.1",
|
63
65
|
"class-validator": "^0.14.0",
|
@@ -65,7 +67,6 @@
|
|
65
67
|
},
|
66
68
|
"dependencies": {
|
67
69
|
"@nestjs/common": "^9.0.0",
|
68
|
-
"@nestjs/throttler": "^4.0.0",
|
69
70
|
"@turf/turf": "^6.5.0",
|
70
71
|
"dotenv": "^16.0.3",
|
71
72
|
"ua-parser-js": "^1.0.35"
|
@@ -82,6 +83,7 @@
|
|
82
83
|
"@nestjs/schematics": "^9.0.0",
|
83
84
|
"@nestjs/swagger": "^6.3.0",
|
84
85
|
"@nestjs/testing": "^9.0.0",
|
86
|
+
"@nestjs/throttler": "^4.0.0",
|
85
87
|
"@types/express": "^4.17.13",
|
86
88
|
"@types/jest": "29.2.4",
|
87
89
|
"@types/node": "18.11.18",
|