@erangamadhushan/express-advanced-error-kit 1.1.0 → 1.3.0

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/index.cjs CHANGED
@@ -62,6 +62,18 @@ var errorMiddleware = (options = {}) => (err, req, res, next) => {
62
62
  } else {
63
63
  console.error(err);
64
64
  }
65
+ const handleMongoError = (err2) => {
66
+ if ((err2 == null ? void 0 : err2.code) === 11e3) {
67
+ const field = Object.keys(err2.keyValue || {})[0];
68
+ return new ApiError(400, `Duplicate value for field: ${field}`);
69
+ }
70
+ return null;
71
+ };
72
+ const mongoError = handleMongoError(err);
73
+ if (mongoError) {
74
+ statusCode = mongoError.statusCode;
75
+ message = mongoError.message;
76
+ }
65
77
  res.status(statusCode).json({
66
78
  success: false,
67
79
  statusCode,
package/dist/index.js CHANGED
@@ -33,6 +33,18 @@ var errorMiddleware = (options = {}) => (err, req, res, next) => {
33
33
  } else {
34
34
  console.error(err);
35
35
  }
36
+ const handleMongoError = (err2) => {
37
+ if ((err2 == null ? void 0 : err2.code) === 11e3) {
38
+ const field = Object.keys(err2.keyValue || {})[0];
39
+ return new ApiError(400, `Duplicate value for field: ${field}`);
40
+ }
41
+ return null;
42
+ };
43
+ const mongoError = handleMongoError(err);
44
+ if (mongoError) {
45
+ statusCode = mongoError.statusCode;
46
+ message = mongoError.message;
47
+ }
36
48
  res.status(statusCode).json({
37
49
  success: false,
38
50
  statusCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erangamadhushan/express-advanced-error-kit",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Advanced TypeScript error handling middleware for Express applications.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,8 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "build": "tsup src/index.ts --format cjs,esm --dts",
12
- "prepublishOnly": "npm run build"
12
+ "prepublishOnly": "npm run build",
13
+ "test": "jest --coverage"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",
@@ -34,8 +35,14 @@
34
35
  "@semantic-release/github": "^12.0.6",
35
36
  "@semantic-release/npm": "^13.1.4",
36
37
  "@types/express": "^5.0.6",
38
+ "@types/jest": "^30.0.0",
39
+ "@types/supertest": "^6.0.3",
37
40
  "conventional-changelog-conventionalcommits": "^9.1.0",
41
+ "express": "^5.2.1",
42
+ "jest": "^30.2.0",
38
43
  "semantic-release": "^25.0.3",
44
+ "supertest": "^7.2.2",
45
+ "ts-jest": "^29.4.6",
39
46
  "tsup": "^8.5.1",
40
47
  "typescript": "^5.9.3"
41
48
  }