@munlib/common 1.0.120 → 1.0.123

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.
@@ -5,6 +5,6 @@ export declare class BadRequestError extends CustomError {
5
5
  constructor(msg: string, statusCode?: number);
6
6
  serializeErrors(): {
7
7
  msg: string;
8
- status: number;
9
- }[];
8
+ status: string;
9
+ };
10
10
  }
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.BadRequestError = void 0;
19
19
  var custom_error_1 = require("./custom-error");
20
+ var erroresStatus_1 = require("./erroresStatus");
20
21
  var BadRequestError = /** @class */ (function (_super) {
21
22
  __extends(BadRequestError, _super);
22
23
  function BadRequestError(msg, statusCode) {
@@ -28,7 +29,7 @@ var BadRequestError = /** @class */ (function (_super) {
28
29
  return _this;
29
30
  }
30
31
  BadRequestError.prototype.serializeErrors = function () {
31
- return [{ msg: this.message, status: this.statusCode }];
32
+ return { msg: this.message, status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()) };
32
33
  };
33
34
  return BadRequestError;
34
35
  }(custom_error_1.CustomError));
@@ -4,5 +4,6 @@ export declare abstract class CustomError extends Error {
4
4
  abstract serializeErrors(): {
5
5
  msg: string;
6
6
  field?: string;
7
- }[];
7
+ status: string;
8
+ };
8
9
  }
@@ -5,5 +5,6 @@ export declare class DatabaseConnectionError extends CustomError {
5
5
  constructor();
6
6
  serializeErrors(): {
7
7
  msg: string;
8
- }[];
8
+ status: string;
9
+ };
9
10
  }
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.DatabaseConnectionError = void 0;
19
19
  var custom_error_1 = require("./custom-error");
20
+ var erroresStatus_1 = require("./erroresStatus");
20
21
  var DatabaseConnectionError = /** @class */ (function (_super) {
21
22
  __extends(DatabaseConnectionError, _super);
22
23
  function DatabaseConnectionError() {
@@ -27,7 +28,7 @@ var DatabaseConnectionError = /** @class */ (function (_super) {
27
28
  return _this;
28
29
  }
29
30
  DatabaseConnectionError.prototype.serializeErrors = function () {
30
- return [{ msg: this.reason }];
31
+ return { msg: this.reason, status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()) };
31
32
  };
32
33
  return DatabaseConnectionError;
33
34
  }(custom_error_1.CustomError));
@@ -3,6 +3,7 @@ export declare class NotAuthorizedError extends CustomError {
3
3
  statusCode: number;
4
4
  constructor();
5
5
  serializeErrors(): {
6
+ status: string;
6
7
  msg: string;
7
- }[];
8
+ };
8
9
  }
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.NotAuthorizedError = void 0;
19
19
  var custom_error_1 = require("./custom-error");
20
+ var erroresStatus_1 = require("./erroresStatus");
20
21
  var NotAuthorizedError = /** @class */ (function (_super) {
21
22
  __extends(NotAuthorizedError, _super);
22
23
  function NotAuthorizedError() {
@@ -26,7 +27,7 @@ var NotAuthorizedError = /** @class */ (function (_super) {
26
27
  return _this;
27
28
  }
28
29
  NotAuthorizedError.prototype.serializeErrors = function () {
29
- return [{ msg: 'Token Not authorized' }];
30
+ return { status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), msg: erroresStatus_1.ErrorController.getErrorMessage(this.statusCode.toString()) };
30
31
  };
31
32
  return NotAuthorizedError;
32
33
  }(custom_error_1.CustomError));
@@ -3,6 +3,7 @@ export declare class NotFoundError extends CustomError {
3
3
  statusCode: number;
4
4
  constructor();
5
5
  serializeErrors(): {
6
+ status: string;
6
7
  msg: string;
7
- }[];
8
+ };
8
9
  }
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.NotFoundError = void 0;
19
19
  var custom_error_1 = require("./custom-error");
20
+ var erroresStatus_1 = require("./erroresStatus");
20
21
  var NotFoundError = /** @class */ (function (_super) {
21
22
  __extends(NotFoundError, _super);
22
23
  function NotFoundError() {
@@ -26,7 +27,7 @@ var NotFoundError = /** @class */ (function (_super) {
26
27
  return _this;
27
28
  }
28
29
  NotFoundError.prototype.serializeErrors = function () {
29
- return [{ msg: 'Not Found' }];
30
+ return { status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), msg: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()) };
30
31
  };
31
32
  return NotFoundError;
32
33
  }(custom_error_1.CustomError));
@@ -8,5 +8,5 @@ export declare class RequestValidationError extends CustomError {
8
8
  status: string;
9
9
  msg: any;
10
10
  field: string;
11
- }[];
11
+ };
12
12
  }
@@ -29,11 +29,7 @@ var RequestValidationError = /** @class */ (function (_super) {
29
29
  return _this;
30
30
  }
31
31
  RequestValidationError.prototype.serializeErrors = function () {
32
- var _this = this;
33
- console.log("22222222", this.errors);
34
- return this.errors.map(function (err) {
35
- return { status: erroresStatus_1.ErrorController.getGeneralStatus(_this.statusCode.toString()), msg: err.msg, field: err.param };
36
- });
32
+ return { status: erroresStatus_1.ErrorController.getGeneralStatus(this.statusCode.toString()), msg: this.errors[0].msg, field: this.errors[0].param };
37
33
  };
38
34
  return RequestValidationError;
39
35
  }(custom_error_1.CustomError));
@@ -6,7 +6,7 @@ var erroresStatus_1 = require("../errors/erroresStatus");
6
6
  var errorHandler = function (err, req, res, next) {
7
7
  // Manejo de errores personalizados
8
8
  if (err instanceof custom_error_1.CustomError) {
9
- return res.status(err.statusCode).send({ errors: err.serializeErrors() });
9
+ return res.status(err.statusCode).send(err.serializeErrors());
10
10
  }
11
11
  // Manejo de errores genéricos
12
12
  var statusCode = 400; // Código de estado por defecto para errores genéricos
@@ -6,7 +6,6 @@ var request_validation_error_1 = require("../errors/request-validation-error");
6
6
  var validateRequest = function (req, res, next) {
7
7
  var errors = (0, express_validator_1.validationResult)(req);
8
8
  if (!errors.isEmpty()) {
9
- console.log("111111111", errors);
10
9
  throw new request_validation_error_1.RequestValidationError(errors.array());
11
10
  }
12
11
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@munlib/common",
3
- "version": "1.0.120",
3
+ "version": "1.0.123",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",