ismx-nexo-node-app 0.4.78 → 0.4.80

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.
@@ -39,12 +39,15 @@ class BusinessErrors {
39
39
  //this.onExcept?.(error)
40
40
  throw error;
41
41
  }
42
- notFound(endpoint) {
43
- this.except("0004", endpoint);
44
- }
45
42
  unauthorized() {
46
43
  this.except("0001");
47
44
  }
45
+ badGateway() {
46
+ this.except("0002");
47
+ }
48
+ notFound(endpoint) {
49
+ this.except("0004", endpoint);
50
+ }
48
51
  getQuery(key, query) {
49
52
  if (!query || !query[key])
50
53
  this.except("0011", key);
@@ -40,6 +40,7 @@ const QueryUtils_1 = __importDefault(require("../repository/utils/QueryUtils"));
40
40
  class BusinessProxy {
41
41
  constructor() {
42
42
  this.modules = {};
43
+ this.onError = (error) => error;
43
44
  }
44
45
  setModules(modules) {
45
46
  this.modules = modules;
@@ -66,7 +67,7 @@ class BusinessProxy {
66
67
  body = JSON.stringify(request.body);
67
68
  }
68
69
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
69
- return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers })).catch((error) => { var _a, _b; return (_b = (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error)) !== null && _b !== void 0 ? _b : error; });
70
+ return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers })).catch((error) => { throw this.onError(error); });
70
71
  });
71
72
  }
72
73
  }
@@ -18,8 +18,9 @@ export default class BusinessErrors {
18
18
  }): void;
19
19
  get(code: string, ...params: string[]): ErrorType;
20
20
  except(code: string, ...params: string[]): never;
21
- notFound(endpoint: string): void;
22
21
  unauthorized(): void;
22
+ badGateway(): void;
23
+ notFound(endpoint: string): void;
23
24
  getQuery(key: string, query: {
24
25
  [key: string]: string;
25
26
  } | undefined): string;
@@ -7,7 +7,7 @@ export interface Module {
7
7
  }
8
8
  export default class BusinessProxy {
9
9
  private modules;
10
- private onError?;
10
+ private onError;
11
11
  setModules(modules: {
12
12
  [key: string]: Module;
13
13
  }): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.78",
3
+ "version": "0.4.80",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -36,14 +36,18 @@ export default class BusinessErrors {
36
36
  throw error;
37
37
  }
38
38
 
39
- notFound(endpoint: string) {
40
- this.except("0004", endpoint)
41
- }
42
-
43
39
  unauthorized() {
44
40
  this.except("0001");
45
41
  }
46
42
 
43
+ badGateway() {
44
+ this.except("0002");
45
+ }
46
+
47
+ notFound(endpoint: string) {
48
+ this.except("0004", endpoint)
49
+ }
50
+
47
51
  getQuery(key: string, query: {[key: string]: string}|undefined): string {
48
52
  if (!query || !query[key]) this.except("0011", key)
49
53
  return query![key];
@@ -12,7 +12,7 @@ export interface Module {
12
12
  export default class BusinessProxy
13
13
  {
14
14
  private modules: {[key:string]: Module} = {};
15
- private onError?: (error: Error) => Error;
15
+ private onError: (error: Error) => Error = (error) => error;
16
16
 
17
17
  setModules(modules: {[key:string]: Module}) {
18
18
  this.modules = modules
@@ -43,6 +43,6 @@ export default class BusinessProxy
43
43
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
44
44
  return fetch(module.host + endpoint + QueryUtils.map(request.query), {
45
45
  ...request, method, body: method !== "GET" ? body : undefined, headers
46
- }).catch((error) => this.onError?.(error) ?? error);
46
+ }).catch((error) => { throw this.onError(error) });
47
47
  }
48
48
  }