badmfck-api-server 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,4 +4,5 @@ declare class DefaultErrors {
4
4
  static UNKNOWN_REQUEST: IError;
5
5
  static JSON_MALFORMED: IError;
6
6
  }
7
+ export declare const isError: (obj: any) => boolean;
7
8
  export default DefaultErrors;
@@ -1,8 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isError = void 0;
4
+ const Validator_1 = require("../helper/Validator");
3
5
  class DefaultErrors {
4
6
  static NOT_IMPLEMENTED = { code: 1, message: "Not implemented" };
5
7
  static UNKNOWN_REQUEST = { code: 2, message: "Unknown request" };
6
8
  static JSON_MALFORMED = { code: 3, message: "JSON malformed" };
7
9
  }
10
+ const isError = (obj) => {
11
+ const isFieldsExists = Validator_1.Validator.validateObject(['code', 'message'], obj);
12
+ if (!isFieldsExists)
13
+ return false;
14
+ if (Validator_1.Validator.validateValue("code", { type: "number" }) !== Validator_1.ValidationReport.OK)
15
+ return false;
16
+ if (Validator_1.Validator.validateValue("message", { type: "string" }) !== Validator_1.ValidationReport.OK)
17
+ return false;
18
+ return true;
19
+ };
20
+ exports.isError = isError;
8
21
  exports.default = DefaultErrors;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",