@orion-js/echoes 2.6.6 → 2.6.12

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,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ class UserError extends Error {
9
+ constructor(code, message, extra) {
10
+ // Calling parent constructor of base Error class.
11
+ if (!message && code) {
12
+ message = code;
13
+ code = 'error';
14
+ }
15
+
16
+ super(message);
17
+ Error.captureStackTrace(this, this.constructor);
18
+ this.isOrionError = true;
19
+ this.isUserError = true;
20
+ this.code = code;
21
+ this.extra = extra;
22
+
23
+ this.getInfo = () => {
24
+ return {
25
+ error: code,
26
+ message,
27
+ extra
28
+ };
29
+ };
30
+ }
31
+
32
+ }
33
+
34
+ exports.default = UserError;
@@ -17,6 +17,10 @@ var _serialize = _interopRequireDefault(require("../publish/serialize"));
17
17
 
18
18
  var _deserialize = _interopRequireDefault(require("../echo/deserialize"));
19
19
 
20
+ var _schema = require("@orion-js/schema");
21
+
22
+ var _UserError = _interopRequireDefault(require("./UserError"));
23
+
20
24
  async function _default({
21
25
  method,
22
26
  service,
@@ -46,16 +50,29 @@ async function _default({
46
50
  });
47
51
 
48
52
  if (result.status !== 200) {
49
- throw new Error(`Echoes request network error ${result.status}`);
53
+ throw new Error(`${result.status}`);
50
54
  }
51
55
 
52
56
  if (result.data.error) {
53
- throw new Error(`Echoes request error: ${result.data.error}`);
57
+ const info = result.data.errorInfo;
58
+
59
+ if (info) {
60
+ if (result.data.isValidationError) {
61
+ throw new _schema.ValidationError(info.validationErrors);
62
+ }
63
+
64
+ if (result.data.isUserError) {
65
+ throw new _UserError.default(info.error, info.message, info.extra);
66
+ }
67
+ }
68
+
69
+ throw new Error(`${result.data.error}`);
54
70
  }
55
71
 
56
72
  const response = (0, _deserialize.default)(result.data.result);
57
73
  return response;
58
74
  } catch (error) {
75
+ if (error.isOrionError) throw error;
59
76
  throw new Error(`Echoes request network error ${error.message}`);
60
77
  }
61
78
  }
@@ -32,10 +32,15 @@ async function _default({
32
32
  result: (0, _serialize.default)(result)
33
33
  };
34
34
  } catch (error) {
35
- console.error('Error at echo requests handler:');
36
- console.error(error);
35
+ if (!error.getInfo) {
36
+ console.error('Error at echo requests handler:', error);
37
+ }
38
+
37
39
  return {
38
- error: error.message
40
+ error: error.message,
41
+ errorInfo: error.getInfo ? error.getInfo() : null,
42
+ isValidationError: !!error.isValidationError,
43
+ isUserError: !!error.isUserError
39
44
  };
40
45
  }
41
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/echoes",
3
- "version": "2.6.6",
3
+ "version": "2.6.12",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -12,7 +12,8 @@
12
12
  "test:watch": "jest src --coverage --watch"
13
13
  },
14
14
  "dependencies": {
15
- "@orion-js/helpers": "^2.6.6",
15
+ "@orion-js/helpers": "^2.6.7",
16
+ "@orion-js/schema": "^3.9.0",
16
17
  "axios": "^0.23.0",
17
18
  "jssha": "^3.2.0",
18
19
  "kafkajs": "^1.15.0",
@@ -28,5 +29,5 @@
28
29
  "publishConfig": {
29
30
  "access": "public"
30
31
  },
31
- "gitHead": "543b3ea5d4bf8d4457ae6604dc2db373b9267a58"
32
+ "gitHead": "54e8771b55b63c2d61b45120f518dc73d59fcb18"
32
33
  }