node-pluginsmanager-plugin 4.8.1 → 4.8.4

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.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ // module
4
+
5
+ module.exports = class NotFoundError extends Error {};
@@ -16,6 +16,7 @@
16
16
 
17
17
  // locals
18
18
  const MediatorUser = require(join(__dirname, "MediatorUser.js"));
19
+ const NotFoundError = require(join(__dirname, "NotFoundError.js"));
19
20
  const { checkInteger, checkNonEmptyObject, checkNonEmptyString } = require(join(__dirname, "..", "checkers", "main.js"));
20
21
  const { extractPattern, extractParams, extractSchemaType } = require(join(__dirname, "..", "utils", "descriptor", "main.js"));
21
22
  const { extractBody, extractIp, extractCookies } = require(join(__dirname, "..", "utils", "request", "main.js"));
@@ -120,12 +121,15 @@ module.exports = class Server extends MediatorUser {
120
121
  req.params = !checkNonEmptyObject("params", req.params, false) ? req.params : extractParams(req.pattern, pathname);
121
122
 
122
123
  // ensure content length formate
123
- if ("string" === typeof req.headers["content-length"]) {
124
+ if ("undefined" === typeof req.headers["content-length"]) {
125
+ req.headers["content-length"] = 0;
126
+ }
127
+ else if ("string" === typeof req.headers["content-length"]) {
124
128
  req.headers["content-length"] = parseInt(req.headers["content-length"], 10);
125
129
  }
126
130
 
127
- // set default content-typ
128
- if ("string" !== typeof req.headers["content-length"]) {
131
+ // set default content-type
132
+ if ("string" !== typeof req.headers["content-type"]) {
129
133
  req.headers["content-type"] = "application/json";
130
134
  }
131
135
 
@@ -186,6 +190,8 @@ module.exports = class Server extends MediatorUser {
186
190
 
187
191
  }).catch((err) => {
188
192
 
193
+ this._log("error", err);
194
+
189
195
  const result = {
190
196
  "code": "INTERNAL_SERVER_ERROR",
191
197
  "message": cleanSendedError(err)
@@ -484,9 +490,22 @@ module.exports = class Server extends MediatorUser {
484
490
  this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
485
491
  return send(req, res, SERVER_CODES.JSON_PARSE, result, this._Descriptor.info.version, this._cors);
486
492
 
493
+ }
494
+ else if (err instanceof NotFoundError) {
495
+
496
+ const result = {
497
+ "code": "NOT_FOUND",
498
+ "message": cleanSendedError(err)
499
+ };
500
+
501
+ this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
502
+ return send(req, res, SERVER_CODES.NOT_FOUND, result, this._Descriptor.info.version, this._cors);
503
+
487
504
  }
488
505
  else {
489
506
 
507
+ this._log("error", err);
508
+
490
509
  const result = {
491
510
  "code": "INTERNAL_SERVER_ERROR",
492
511
  "message": cleanSendedError(err)
@@ -11,6 +11,7 @@
11
11
  const MediatorUser = require(join(__dirname, "MediatorUser.js"));
12
12
  const Orchestrator = require(join(__dirname, "Orchestrator.js"));
13
13
  const Server = require(join(__dirname, "Server.js"));
14
+ const NotFoundError = require(join(__dirname, "NotFoundError.js"));
14
15
 
15
16
  // module
16
17
 
@@ -19,5 +20,6 @@ module.exports = {
19
20
  Mediator,
20
21
  MediatorUser,
21
22
  Orchestrator,
22
- Server
23
+ Server,
24
+ NotFoundError
23
25
  };
package/lib/index.d.ts CHANGED
@@ -206,4 +206,6 @@ declare module "node-pluginsmanager-plugin" {
206
206
 
207
207
  }
208
208
 
209
+ export class NotFoundError extends Error {}
210
+
209
211
  }
@@ -8,6 +8,7 @@
8
8
  "WRONG_TYPE_PARAMETER": 400,
9
9
  "EMPTY_OR_RANGE_OR_ENUM_PARAMETER": 400,
10
10
  "JSON_PARSE": 400,
11
+ "NOT_FOUND": 404,
11
12
  "MISSING_HEADER": 411,
12
13
 
13
14
  "INTERNAL_SERVER_ERROR": 500,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-pluginsmanager-plugin",
3
- "version": "4.8.1",
3
+ "version": "4.8.4",
4
4
  "description": "An abstract parent plugin for node-pluginsmanager",
5
5
  "main": "lib/main.js",
6
6
  "typings": "lib/index.d.ts",
@@ -39,21 +39,21 @@
39
39
  "express-openapi-validate": "0.6.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "17.0.25",
42
+ "@types/node": "17.0.31",
43
43
  "@types/socket.io": "3.0.2",
44
44
  "@types/ws": "8.5.3",
45
45
  "check-version-modules": "1.3.5",
46
46
  "coveralls": "3.1.1",
47
47
  "colors": "1.4.0",
48
- "eslint": "8.13.0",
49
- "express": "4.17.3",
48
+ "eslint": "8.14.0",
49
+ "express": "4.18.1",
50
50
  "husky": "7.0.4",
51
- "mocha": "9.2.2",
51
+ "mocha": "10.0.0",
52
52
  "nyc": "15.1.0",
53
- "socket.io": "4.4.1",
54
- "socket.io-client": "4.4.1",
55
- "typescript": "4.6.3",
56
- "ws": "8.5.0"
53
+ "socket.io": "4.5.0",
54
+ "socket.io-client": "4.5.0",
55
+ "typescript": "4.6.4",
56
+ "ws": "8.6.0"
57
57
  },
58
58
  "homepage": "https://github.com/Psychopoulet/node-pluginsmanager-plugin#readme",
59
59
  "engines": {
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- // module
4
-
5
- module.exports = function errToString (err) {
6
-
7
- if ("string" === typeof err) {
8
- return err;
9
- }
10
- else if ("object" === typeof err && err.message) {
11
- return err.message;
12
- }
13
- else {
14
- return "";
15
- }
16
-
17
- };