@munlib/common 1.0.170 → 1.0.178

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.
@@ -7,5 +7,7 @@ export declare class BadRequestError extends CustomError {
7
7
  status: string;
8
8
  msg: string;
9
9
  code: string;
10
+ typeMsg: string;
11
+ userMsg: string;
10
12
  };
11
13
  }
@@ -16,20 +16,29 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.BadRequestError = void 0;
19
+ var instituciones_pagos_1 = require("../events/types/instituciones-pagos");
19
20
  var custom_error_1 = require("./custom-error");
20
21
  var erroresStatus_1 = require("./erroresStatus");
21
22
  var BadRequestError = /** @class */ (function (_super) {
22
23
  __extends(BadRequestError, _super);
23
24
  function BadRequestError(msg, statusCode) {
24
- var _this = _super.call(this, msg) || this;
25
+ var _this = _super.call(this, msg, "", "") || this;
25
26
  _this.msg = msg;
26
27
  _this.statusCode = 400;
27
28
  _this.statusCode = statusCode ? _this.statusCode : 400;
29
+ _this.typeMsg = instituciones_pagos_1.ErrorCategories.MIDDLEWARE;
30
+ _this.userMsg = erroresStatus_1.ErrorController.getErrorMessage(instituciones_pagos_1.ErrorCategories.MIDDLEWARE);
28
31
  Object.setPrototypeOf(_this, BadRequestError.prototype);
29
32
  return _this;
30
33
  }
31
34
  BadRequestError.prototype.serializeErrors = function () {
32
- return { status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), msg: this.message, code: this.statusCode.toString() };
35
+ return {
36
+ status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
37
+ msg: this.message,
38
+ code: this.statusCode.toString(),
39
+ typeMsg: this.typeMsg,
40
+ userMsg: this.userMsg
41
+ };
33
42
  };
34
43
  return BadRequestError;
35
44
  }(custom_error_1.CustomError));
@@ -1,13 +1,13 @@
1
1
  export declare abstract class CustomError extends Error {
2
- typeError?: string | undefined;
3
- userMsg?: string | undefined;
2
+ typeMsg: string;
3
+ userMsg: string;
4
4
  abstract statusCode: number;
5
- constructor(msg: string, typeError?: string | undefined, userMsg?: string | undefined);
5
+ constructor(msg: string, typeMsg: string, userMsg: string);
6
6
  abstract serializeErrors(): {
7
7
  msg: string;
8
8
  status: string;
9
9
  code: string;
10
- typeError?: string;
11
- userMsg?: string;
10
+ typeMsg: string;
11
+ userMsg: string;
12
12
  };
13
13
  }
@@ -18,9 +18,9 @@ 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, typeError, userMsg) {
21
+ function CustomError(msg, typeMsg, userMsg) {
22
22
  var _this = _super.call(this, msg) || this;
23
- _this.typeError = typeError;
23
+ _this.typeMsg = typeMsg;
24
24
  _this.userMsg = userMsg;
25
25
  Object.setPrototypeOf(_this, CustomError.prototype);
26
26
  return _this;
@@ -1,11 +1,15 @@
1
1
  import { CustomError } from './custom-error';
2
2
  export declare class DatabaseConnectionError extends CustomError {
3
+ typeMsg: string;
4
+ userMsg: string;
3
5
  statusCode: number;
4
6
  reason: string;
5
- constructor();
7
+ constructor(typeMsg?: string, userMsg?: string);
6
8
  serializeErrors(): {
7
9
  msg: string;
8
10
  status: string;
9
11
  code: string;
12
+ typeMsg: string;
13
+ userMsg: string;
10
14
  };
11
15
  }
@@ -16,19 +16,32 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.DatabaseConnectionError = void 0;
19
+ var instituciones_pagos_1 = require("../events/types/instituciones-pagos");
19
20
  var custom_error_1 = require("./custom-error");
20
21
  var erroresStatus_1 = require("./erroresStatus");
21
22
  var DatabaseConnectionError = /** @class */ (function (_super) {
22
23
  __extends(DatabaseConnectionError, _super);
23
- function DatabaseConnectionError() {
24
- var _this = _super.call(this, 'Error connecting to db') || this;
24
+ function DatabaseConnectionError(typeMsg, userMsg) {
25
+ if (typeMsg === void 0) { typeMsg = instituciones_pagos_1.ErrorCategories.MIDDLEWARE; }
26
+ if (userMsg === void 0) { userMsg = erroresStatus_1.ErrorController.getErrorMessage(instituciones_pagos_1.ErrorCategories.MIDDLEWARE); }
27
+ var _this = _super.call(this, 'Error connecting to db', "", "") || this;
28
+ _this.typeMsg = typeMsg;
29
+ _this.userMsg = userMsg;
25
30
  _this.statusCode = 500;
26
31
  _this.reason = 'Error connecting to database';
32
+ _this.typeMsg = _this.typeMsg;
33
+ _this.userMsg = _this.userMsg;
27
34
  Object.setPrototypeOf(_this, DatabaseConnectionError.prototype);
28
35
  return _this;
29
36
  }
30
37
  DatabaseConnectionError.prototype.serializeErrors = function () {
31
- return { msg: this.reason, status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), code: this.statusCode.toString() };
38
+ return {
39
+ msg: this.reason,
40
+ status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
41
+ code: this.statusCode.toString(),
42
+ typeMsg: this.typeMsg,
43
+ userMsg: this.userMsg
44
+ };
32
45
  };
33
46
  return DatabaseConnectionError;
34
47
  }(custom_error_1.CustomError));
@@ -3,30 +3,18 @@ export declare class GenericError extends CustomError {
3
3
  msg: string;
4
4
  httpStatus: number;
5
5
  code: string;
6
- typeError: string;
6
+ typeMsg: string;
7
7
  userMsg: string;
8
8
  statusCode: number;
9
9
  constructor(msg: string, httpStatus: number, // Mensaje principal del error
10
10
  code?: string, // Código de estado (por defecto 500)
11
- typeError?: string, // Tipo de error opcional
11
+ typeMsg?: string, // Tipo de error opcional
12
12
  userMsg?: string);
13
13
  serializeErrors(): {
14
14
  msg: string;
15
15
  status: string;
16
16
  code: string;
17
- typeError: string;
18
- userMsg: string;
19
- };
20
- }
21
- export declare class ValidationError extends CustomError {
22
- userMsg: string;
23
- statusCode: number;
24
- constructor(msg: string, userMsg: string);
25
- serializeErrors(): {
26
- msg: string;
27
- status: string;
28
- code: string;
29
- typeError: string | undefined;
17
+ typeMsg: string;
30
18
  userMsg: string;
31
19
  };
32
20
  }
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ValidationError = exports.GenericError = void 0;
18
+ exports.GenericError = void 0;
19
19
  var instituciones_pagos_1 = require("../events/types/instituciones-pagos");
20
20
  var custom_error_1 = require("./custom-error"); // Asegúrate de importar tu clase base
21
21
  var erroresStatus_1 = require("./erroresStatus");
@@ -23,21 +23,21 @@ var GenericError = /** @class */ (function (_super) {
23
23
  __extends(GenericError, _super);
24
24
  function GenericError(msg, httpStatus, // Mensaje principal del error
25
25
  code, // Código de estado (por defecto 500)
26
- typeError, // Tipo de error opcional
26
+ typeMsg, // Tipo de error opcional
27
27
  userMsg // Mensaje amigable para el usuario
28
28
  ) {
29
29
  if (code === void 0) { code = "500"; }
30
- if (typeError === void 0) { typeError = instituciones_pagos_1.ErrorCategories.MIDDLEWARE; }
30
+ if (typeMsg === void 0) { typeMsg = instituciones_pagos_1.ErrorCategories.MIDDLEWARE; }
31
31
  if (userMsg === void 0) { userMsg = erroresStatus_1.ErrorController.getErrorMessage(instituciones_pagos_1.ErrorCategories.MIDDLEWARE); }
32
- var _this = _super.call(this, msg, typeError, userMsg) || this;
32
+ var _this = _super.call(this, msg, typeMsg, userMsg) || this;
33
33
  _this.msg = msg;
34
34
  _this.httpStatus = httpStatus;
35
35
  _this.code = code;
36
- _this.typeError = typeError;
36
+ _this.typeMsg = typeMsg;
37
37
  _this.userMsg = userMsg;
38
38
  _this.statusCode = _this.httpStatus;
39
39
  _this.msg = erroresStatus_1.ErrorController.getErrorMessage(code) || _this.message;
40
- _this.typeError = _this.typeError;
40
+ _this.typeMsg = _this.typeMsg;
41
41
  _this.userMsg = _this.userMsg;
42
42
  Object.setPrototypeOf(_this, GenericError.prototype);
43
43
  return _this;
@@ -47,31 +47,10 @@ var GenericError = /** @class */ (function (_super) {
47
47
  msg: this.message,
48
48
  status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
49
49
  code: this.code.toString(),
50
- typeError: this.typeError,
50
+ typeMsg: this.typeMsg,
51
51
  userMsg: this.userMsg
52
52
  };
53
53
  };
54
54
  return GenericError;
55
55
  }(custom_error_1.CustomError));
56
56
  exports.GenericError = GenericError;
57
- var ValidationError = /** @class */ (function (_super) {
58
- __extends(ValidationError, _super);
59
- function ValidationError(msg, userMsg) {
60
- var _this = _super.call(this, msg, "VALIDATION_ERROR", userMsg) || this;
61
- _this.userMsg = userMsg;
62
- _this.statusCode = 400;
63
- Object.setPrototypeOf(_this, ValidationError.prototype);
64
- return _this;
65
- }
66
- ValidationError.prototype.serializeErrors = function () {
67
- return {
68
- msg: this.message,
69
- status: "validation_failed",
70
- code: "VALIDATION_ERROR",
71
- typeError: this.typeError,
72
- userMsg: this.userMsg,
73
- };
74
- };
75
- return ValidationError;
76
- }(custom_error_1.CustomError));
77
- exports.ValidationError = ValidationError;
@@ -1,12 +1,12 @@
1
1
  import { CustomError } from './custom-error';
2
2
  export declare class NotAuthorizedError extends CustomError {
3
3
  statusCode: number;
4
- constructor(typeError?: string, userMsg?: string);
4
+ constructor(typeMsg: 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
+ typeMsg: string;
10
+ userMsg: string;
11
11
  };
12
12
  }
@@ -20,9 +20,11 @@ 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(typeError, userMsg) {
24
- var _this = _super.call(this, 'Not Authorized', typeError, userMsg) || this;
23
+ function NotAuthorizedError(typeMsg, userMsg) {
24
+ var _this = _super.call(this, 'Not Authorized', typeMsg, userMsg) || this;
25
25
  _this.statusCode = 401;
26
+ _this.typeMsg = _this.typeMsg;
27
+ _this.userMsg = _this.userMsg;
26
28
  Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
27
29
  return _this;
28
30
  }
@@ -31,7 +33,7 @@ var NotAuthorizedError = /** @class */ (function (_super) {
31
33
  status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
32
34
  msg: erroresStatus_1.ErrorController.getErrorMessage(this.statusCode.toString()),
33
35
  code: this.statusCode.toString(),
34
- typeError: this.typeError, // Añadir typeError
36
+ typeMsg: this.typeMsg, // Añadir typeError
35
37
  userMsg: this.userMsg, // Añadir userMsg
36
38
  };
37
39
  };
@@ -6,5 +6,7 @@ export declare class NotFoundError extends CustomError {
6
6
  status: string;
7
7
  msg: string;
8
8
  code: string;
9
+ typeMsg: string;
10
+ userMsg: string;
9
11
  };
10
12
  }
@@ -21,13 +21,21 @@ var erroresStatus_1 = require("./erroresStatus");
21
21
  var NotFoundError = /** @class */ (function (_super) {
22
22
  __extends(NotFoundError, _super);
23
23
  function NotFoundError() {
24
- var _this = _super.call(this, 'Route not found') || this;
24
+ var _this = _super.call(this, 'Route not found', "", "") || this;
25
25
  _this.statusCode = 404;
26
+ _this.typeMsg = _this.typeMsg;
27
+ _this.userMsg = _this.userMsg;
26
28
  Object.setPrototypeOf(_this, NotFoundError.prototype);
27
29
  return _this;
28
30
  }
29
31
  NotFoundError.prototype.serializeErrors = function () {
30
- return { status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), msg: erroresStatus_1.ErrorController.getErrorMessage(this.statusCode.toString()), code: this.statusCode.toString() };
32
+ return {
33
+ status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
34
+ msg: erroresStatus_1.ErrorController.getErrorMessage(this.statusCode.toString()),
35
+ code: this.statusCode.toString(),
36
+ typeMsg: this.typeMsg,
37
+ userMsg: this.userMsg
38
+ };
31
39
  };
32
40
  return NotFoundError;
33
41
  }(custom_error_1.CustomError));
@@ -2,12 +2,15 @@ import { ValidationError } from 'express-validator';
2
2
  import { CustomError } from './custom-error';
3
3
  export declare class RequestValidationError extends CustomError {
4
4
  errors: ValidationError[];
5
+ typeMsg: string;
6
+ userMsg: string;
5
7
  statusCode: number;
6
- constructor(errors: ValidationError[]);
8
+ constructor(errors: ValidationError[], typeMsg?: string, userMsg?: string);
7
9
  serializeErrors(): {
8
10
  status: string;
9
11
  msg: any;
10
- field: string;
11
12
  code: string;
13
+ typeMsg: string;
14
+ userMsg: string;
12
15
  };
13
16
  }
@@ -18,18 +18,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.RequestValidationError = void 0;
19
19
  var custom_error_1 = require("./custom-error");
20
20
  var erroresStatus_1 = require("./erroresStatus");
21
+ var instituciones_pagos_1 = require("../events/types/instituciones-pagos");
21
22
  var RequestValidationError = /** @class */ (function (_super) {
22
23
  __extends(RequestValidationError, _super);
23
- function RequestValidationError(errors) {
24
- var _this = _super.call(this, 'Invalid request parameters') || this;
24
+ function RequestValidationError(errors, typeMsg, userMsg) {
25
+ if (typeMsg === void 0) { typeMsg = instituciones_pagos_1.ErrorCategories.SINTAX; }
26
+ if (userMsg === void 0) { userMsg = erroresStatus_1.ErrorController.getErrorMessage(instituciones_pagos_1.ErrorCategories.SINTAX); }
27
+ var _this = _super.call(this, 'Invalid request parameters', "", "") || this;
25
28
  _this.errors = errors;
29
+ _this.typeMsg = typeMsg;
30
+ _this.userMsg = userMsg;
26
31
  _this.statusCode = 400;
32
+ _this.typeMsg = _this.typeMsg;
33
+ _this.userMsg = _this.userMsg;
27
34
  // Only because we are extending a built in class
28
35
  Object.setPrototypeOf(_this, RequestValidationError.prototype);
29
36
  return _this;
30
37
  }
31
38
  RequestValidationError.prototype.serializeErrors = function () {
32
- return { status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), msg: this.errors[0].msg, field: this.errors[0].param, code: this.statusCode.toString() };
39
+ return {
40
+ status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()),
41
+ msg: this.errors[0].msg,
42
+ code: this.statusCode.toString(),
43
+ typeMsg: this.typeMsg,
44
+ userMsg: this.userMsg
45
+ };
33
46
  };
34
47
  return RequestValidationError;
35
48
  }(custom_error_1.CustomError));
package/build/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './errors/bad-request-error';
2
1
  export * from './errors/custom-error';
3
2
  export * from './errors/database-connection-error';
4
3
  export * from './errors/not-authorized-error';
package/build/index.js CHANGED
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // Re-export stuff from errors and middlewares
18
- __exportStar(require("./errors/bad-request-error"), exports);
19
18
  __exportStar(require("./errors/custom-error"), exports);
20
19
  __exportStar(require("./errors/database-connection-error"), exports);
21
20
  __exportStar(require("./errors/not-authorized-error"), exports);
@@ -15,7 +15,7 @@ var errorHandler = function (err, req, res, next) {
15
15
  status: erroresStatus_1.ErrorController.getGeneralStatus(statusCode.toString()) || "error",
16
16
  msg: err.message, // Agregar el código de estado al objeto de errores
17
17
  code: statusCode,
18
- typeError: instituciones_pagos_1.ErrorCategories.MIDDLEWARE,
18
+ typeMsg: instituciones_pagos_1.ErrorCategories.MIDDLEWARE,
19
19
  userMsg: erroresStatus_1.ErrorController.getErrorMessage("MIDDLEWARE")
20
20
  });
21
21
  };
@@ -10,7 +10,7 @@ var requireAuth = function (req, res, next) {
10
10
  // Extraer el JWT del encabezado de autorización
11
11
  var authorizationHeader = req.headers["authorization"];
12
12
  if (!authorizationHeader || !authorizationHeader.startsWith("Bearer ")) {
13
- throw new not_authorized_error_1.NotAuthorizedError();
13
+ throw new not_authorized_error_1.NotAuthorizedError("", "");
14
14
  }
15
15
  var token = authorizationHeader.split(" ")[1];
16
16
  try {
@@ -20,7 +20,7 @@ var requireAuth = function (req, res, next) {
20
20
  }
21
21
  catch (err) {
22
22
  console.log("Error al verificar el token:", err);
23
- throw new not_authorized_error_1.NotAuthorizedError();
23
+ throw new not_authorized_error_1.NotAuthorizedError("", "");
24
24
  }
25
25
  next();
26
26
  };
@@ -29,7 +29,7 @@ var requireAuthAdmin = function (req, res, next) {
29
29
  // Extraer el JWT del encabezado de autorización
30
30
  var authorizationHeader = req.headers["authorization"];
31
31
  if (!authorizationHeader || !authorizationHeader.startsWith("Bearer ")) {
32
- throw new not_authorized_error_1.NotAuthorizedError();
32
+ throw new not_authorized_error_1.NotAuthorizedError("", "");
33
33
  }
34
34
  var token = authorizationHeader.split(" ")[1];
35
35
  try {
@@ -37,12 +37,12 @@ var requireAuthAdmin = function (req, res, next) {
37
37
  var payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
38
38
  req.currentUser = payload;
39
39
  if (!payload.isAdmin) {
40
- throw new not_authorized_error_1.NotAuthorizedError();
40
+ throw new not_authorized_error_1.NotAuthorizedError("", "");
41
41
  }
42
42
  }
43
43
  catch (err) {
44
44
  console.log("Error al verificar el token:", err);
45
- throw new not_authorized_error_1.NotAuthorizedError();
45
+ throw new not_authorized_error_1.NotAuthorizedError("", "");
46
46
  }
47
47
  next();
48
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@munlib/common",
3
- "version": "1.0.170",
3
+ "version": "1.0.178",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",