@konplit-services/common 1.0.10 → 1.0.11

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.
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errorHandler = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
- const custom_error_1 = require("../errors/custom-error");
6
- const status_1 = require("../helper/status");
7
- const error_codes_1 = require("../helper/errorCodes/error-codes");
5
+ const errors_1 = require("../errors");
6
+ const helper_1 = require("../helper");
7
+ const helper_2 = require("../helper");
8
8
  const errorHandler = (err, req, res, next) => {
9
- if (err instanceof custom_error_1.CustomError) {
10
- console.log(err);
9
+ if (err instanceof errors_1.CustomError) {
10
+ console.log("custome error", err);
11
11
  return res.status(err.statusCode).send(err.sequalizeErrors());
12
12
  }
13
13
  if (err instanceof mongoose_1.Error.ValidationError) {
@@ -19,8 +19,8 @@ const errorHandler = (err, req, res, next) => {
19
19
  };
20
20
  });
21
21
  return res.status(400).send({
22
- status: status_1.Status.Failed,
23
- data: result,
22
+ status: helper_1.Status.Failed,
23
+ errors: result,
24
24
  });
25
25
  }
26
26
  //@ts-ignore
@@ -31,20 +31,20 @@ const errorHandler = (err, req, res, next) => {
31
31
  const value = Object.values(err.keyValue)[0];
32
32
  const error_data = {
33
33
  message: `${value} already exist!`,
34
- error_code: `${error_codes_1.error_codes.DUPLICATE_VALUE}`,
34
+ error_code: `${helper_2.error_codes.DUPLICATE_VALUE}`,
35
35
  field: `${key}`,
36
36
  };
37
37
  return res.status(400).send({
38
- status: status_1.Status.Failed,
39
- data: [error_data],
38
+ status: helper_1.Status.Failed,
39
+ errors: [error_data],
40
40
  });
41
41
  }
42
42
  //@ts-ignore
43
43
  if (err instanceof SyntaxError && err.status === 400 && "body" in err) {
44
44
  // Handle JSON parsing error
45
45
  return res.status(400).send({
46
- status: status_1.Status.Failed,
47
- data: [
46
+ status: helper_1.Status.Failed,
47
+ errors: [
48
48
  {
49
49
  message: "Invalid JSON Body",
50
50
  error_code: `JSON_REQUEST_BODY`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",