@munlib/common 1.0.156 → 1.0.159
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/build/errors/custom-error.d.ts +5 -2
- package/build/errors/custom-error.js +3 -1
- package/build/errors/erroresStatus.js +11 -2
- package/build/errors/genericError.d.ts +19 -0
- package/build/errors/genericError.js +52 -0
- package/build/errors/not-authorized-error.d.ts +3 -1
- package/build/errors/not-authorized-error.js +9 -3
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/middlewares/error-handler.js +6 -7
- package/package.json +1 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export declare abstract class CustomError extends Error {
|
|
2
|
+
typeError?: string | undefined;
|
|
3
|
+
userMsg?: string | undefined;
|
|
2
4
|
abstract statusCode: number;
|
|
3
|
-
constructor(msg: string);
|
|
5
|
+
constructor(msg: string, typeError?: string | undefined, userMsg?: string | undefined);
|
|
4
6
|
abstract serializeErrors(): {
|
|
5
7
|
msg: string;
|
|
6
|
-
field?: string;
|
|
7
8
|
status: string;
|
|
8
9
|
code: string;
|
|
10
|
+
typeError?: string;
|
|
11
|
+
userMsg?: string;
|
|
9
12
|
};
|
|
10
13
|
}
|
|
@@ -18,8 +18,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.CustomError = void 0;
|
|
19
19
|
var CustomError = /** @class */ (function (_super) {
|
|
20
20
|
__extends(CustomError, _super);
|
|
21
|
-
function CustomError(msg) {
|
|
21
|
+
function CustomError(msg, typeError, userMsg) {
|
|
22
22
|
var _this = _super.call(this, msg) || this;
|
|
23
|
+
_this.typeError = typeError;
|
|
24
|
+
_this.userMsg = userMsg;
|
|
23
25
|
Object.setPrototypeOf(_this, CustomError.prototype);
|
|
24
26
|
return _this;
|
|
25
27
|
}
|
|
@@ -75,7 +75,7 @@ exports.errorCodes = {
|
|
|
75
75
|
"M010": "No se puede procesar una orden que ya fue pagada",
|
|
76
76
|
"M011": "Error al consultar Rubros",
|
|
77
77
|
"M012": "La Consulta se realizo con exito",
|
|
78
|
-
"M013": "
|
|
78
|
+
"M013": "API Key de Middleware Invalida",
|
|
79
79
|
"M014": "Error al generar comprobante de pago",
|
|
80
80
|
"M015": "Error al obtener Total Pagado",
|
|
81
81
|
"M016": "Error al obtener Comprobante de una orden no pagada/reversada",
|
|
@@ -134,6 +134,11 @@ exports.errorCodes = {
|
|
|
134
134
|
"ERR_BAD_RESPONSE": "El servidor respondio, pero la respuesta no fue valida.",
|
|
135
135
|
"ERR_TIMEOUT": "La solicitud tomo demasiado tiempo para completarse",
|
|
136
136
|
"ERR_CANCELED": "La solicitud fue cancelada antes de completarse.",
|
|
137
|
+
//Errores Especificos PARA EL USURIO
|
|
138
|
+
"MIDDLEWARE": "Error interno de Sistema. Inténtelo nuevamente más tarde.",
|
|
139
|
+
"USUARIO": "",
|
|
140
|
+
"TECNICO": "Hemos encontrado un problema al procesar su solicitud. Inténtelo nuevamente más tarde.",
|
|
141
|
+
"SUCCESS": "",
|
|
137
142
|
};
|
|
138
143
|
exports.statusCodeMapping = {
|
|
139
144
|
"E000": "success",
|
|
@@ -269,7 +274,11 @@ exports.statusCodeMapping = {
|
|
|
269
274
|
"ERR_NETWORK": "error",
|
|
270
275
|
"ERR_BAD_RESPONSE": "error",
|
|
271
276
|
"ERR_TIMEOUT": "error",
|
|
272
|
-
"ERR_CANCELED": "error"
|
|
277
|
+
"ERR_CANCELED": "error",
|
|
278
|
+
"MIDDLEWARE": "error",
|
|
279
|
+
"USUARIO": "error",
|
|
280
|
+
"TECNICO": "error",
|
|
281
|
+
"SUCCESS": "success",
|
|
273
282
|
};
|
|
274
283
|
var ErrorController = /** @class */ (function () {
|
|
275
284
|
function ErrorController() {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CustomError } from './custom-error';
|
|
2
|
+
export declare class GenericError extends CustomError {
|
|
3
|
+
msg: string;
|
|
4
|
+
code: string;
|
|
5
|
+
typeError: string;
|
|
6
|
+
userMsg: string;
|
|
7
|
+
statusCode: number;
|
|
8
|
+
constructor(msg: string, // Mensaje principal del error
|
|
9
|
+
code?: string, // Código de estado (por defecto 500)
|
|
10
|
+
typeError?: string, // Tipo de error opcional
|
|
11
|
+
userMsg?: string);
|
|
12
|
+
serializeErrors(): {
|
|
13
|
+
msg: string;
|
|
14
|
+
status: string;
|
|
15
|
+
code: string;
|
|
16
|
+
typeError: string;
|
|
17
|
+
userMsg: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.GenericError = void 0;
|
|
19
|
+
var custom_error_1 = require("./custom-error"); // Asegúrate de importar tu clase base
|
|
20
|
+
var erroresStatus_1 = require("./erroresStatus");
|
|
21
|
+
var GenericError = /** @class */ (function (_super) {
|
|
22
|
+
__extends(GenericError, _super);
|
|
23
|
+
function GenericError(msg, // Mensaje principal del error
|
|
24
|
+
code, // Código de estado (por defecto 500)
|
|
25
|
+
typeError, // Tipo de error opcional
|
|
26
|
+
userMsg // Mensaje amigable para el usuario
|
|
27
|
+
) {
|
|
28
|
+
if (code === void 0) { code = "500"; }
|
|
29
|
+
if (typeError === void 0) { typeError = "INTERNAL_SERVER_ERROR"; }
|
|
30
|
+
if (userMsg === void 0) { userMsg = "Hemos encontrado un problema. Inténtelo nuevamente más tarde."; }
|
|
31
|
+
var _this = _super.call(this, msg, typeError, userMsg) || this;
|
|
32
|
+
_this.msg = msg;
|
|
33
|
+
_this.code = code;
|
|
34
|
+
_this.typeError = typeError;
|
|
35
|
+
_this.userMsg = userMsg;
|
|
36
|
+
_this.statusCode = parseInt(code); // Convertir el código a número para HTTP
|
|
37
|
+
_this.msg = erroresStatus_1.ErrorController.getErrorMessage(code) || _this.message;
|
|
38
|
+
Object.setPrototypeOf(_this, GenericError.prototype);
|
|
39
|
+
return _this;
|
|
40
|
+
}
|
|
41
|
+
GenericError.prototype.serializeErrors = function () {
|
|
42
|
+
return {
|
|
43
|
+
msg: this.message,
|
|
44
|
+
status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
|
|
45
|
+
code: this.code.toString(),
|
|
46
|
+
typeError: this.typeError,
|
|
47
|
+
userMsg: this.userMsg
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
return GenericError;
|
|
51
|
+
}(custom_error_1.CustomError));
|
|
52
|
+
exports.GenericError = GenericError;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CustomError } from './custom-error';
|
|
2
2
|
export declare class NotAuthorizedError extends CustomError {
|
|
3
3
|
statusCode: number;
|
|
4
|
-
constructor();
|
|
4
|
+
constructor(typeError?: string, userMsg?: string);
|
|
5
5
|
serializeErrors(): {
|
|
6
6
|
status: string;
|
|
7
7
|
msg: string;
|
|
8
8
|
code: string;
|
|
9
|
+
typeError: string | undefined;
|
|
10
|
+
userMsg: string | undefined;
|
|
9
11
|
};
|
|
10
12
|
}
|
|
@@ -20,14 +20,20 @@ var custom_error_1 = require("./custom-error");
|
|
|
20
20
|
var erroresStatus_1 = require("./erroresStatus");
|
|
21
21
|
var NotAuthorizedError = /** @class */ (function (_super) {
|
|
22
22
|
__extends(NotAuthorizedError, _super);
|
|
23
|
-
function NotAuthorizedError() {
|
|
24
|
-
var _this = _super.call(this, 'Not Authorized') || this;
|
|
23
|
+
function NotAuthorizedError(typeError, userMsg) {
|
|
24
|
+
var _this = _super.call(this, 'Not Authorized', typeError, userMsg) || this;
|
|
25
25
|
_this.statusCode = 401;
|
|
26
26
|
Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
|
|
27
27
|
return _this;
|
|
28
28
|
}
|
|
29
29
|
NotAuthorizedError.prototype.serializeErrors = function () {
|
|
30
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
|
|
32
|
+
msg: erroresStatus_1.ErrorController.getErrorMessage(this.statusCode.toString()),
|
|
33
|
+
code: this.statusCode.toString(),
|
|
34
|
+
typeError: this.typeError, // Añadir typeError
|
|
35
|
+
userMsg: this.userMsg, // Añadir userMsg
|
|
36
|
+
};
|
|
31
37
|
};
|
|
32
38
|
return NotAuthorizedError;
|
|
33
39
|
}(custom_error_1.CustomError));
|
package/build/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './errors/database-connection-error';
|
|
|
4
4
|
export * from './errors/not-authorized-error';
|
|
5
5
|
export * from './errors/not-found-error';
|
|
6
6
|
export * from './errors/request-validation-error';
|
|
7
|
+
export * from './errors/genericError';
|
|
7
8
|
export * from './middlewares/error-handler';
|
|
8
9
|
export * from './middlewares/require-auth';
|
|
9
10
|
export * from './middlewares/validate-request';
|
package/build/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./errors/database-connection-error"), exports);
|
|
|
21
21
|
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
22
22
|
__exportStar(require("./errors/not-found-error"), exports);
|
|
23
23
|
__exportStar(require("./errors/request-validation-error"), exports);
|
|
24
|
+
__exportStar(require("./errors/genericError"), exports);
|
|
24
25
|
//export * from './middlewares/current-user';
|
|
25
26
|
__exportStar(require("./middlewares/error-handler"), exports);
|
|
26
27
|
__exportStar(require("./middlewares/require-auth"), exports);
|
|
@@ -3,20 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.errorHandler = void 0;
|
|
4
4
|
var custom_error_1 = require("../errors/custom-error");
|
|
5
5
|
var erroresStatus_1 = require("../errors/erroresStatus");
|
|
6
|
-
//import {apmInstance} from './apm';
|
|
7
6
|
var errorHandler = function (err, req, res, next) {
|
|
8
|
-
//
|
|
9
|
-
//apmInstance.captureError(err);
|
|
10
|
-
// Manejo de errores personalizados
|
|
7
|
+
var statusCode = 500; // Código de estado por defecto para errores genéricos
|
|
11
8
|
if (err instanceof custom_error_1.CustomError) {
|
|
9
|
+
console.log("ENTRA A CUSTOM ERROR******");
|
|
12
10
|
return res.status(err.statusCode).send(err.serializeErrors());
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
var statusCode = 400; // Código de estado por defecto para errores genéricos
|
|
12
|
+
console.log("NO===> ENTRA A CUSTOM ERROR");
|
|
16
13
|
res.status(statusCode).send({
|
|
17
14
|
status: erroresStatus_1.ErrorController.getGeneralStatus(statusCode.toString()),
|
|
18
15
|
msg: err.message, // Agregar el código de estado al objeto de errores
|
|
19
|
-
code: statusCode
|
|
16
|
+
code: statusCode,
|
|
17
|
+
typeError: "Middleware",
|
|
18
|
+
userMsg: ""
|
|
20
19
|
});
|
|
21
20
|
};
|
|
22
21
|
exports.errorHandler = errorHandler;
|