ismx-nexo-node-app 0.4.77 → 0.4.78
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.
|
@@ -44,6 +44,9 @@ class BusinessProxy {
|
|
|
44
44
|
setModules(modules) {
|
|
45
45
|
this.modules = modules;
|
|
46
46
|
}
|
|
47
|
+
setOnError(onError) {
|
|
48
|
+
this.onError = onError;
|
|
49
|
+
}
|
|
47
50
|
call(tag, method, endpoint, request) {
|
|
48
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
52
|
var _a, _b;
|
|
@@ -63,12 +66,7 @@ class BusinessProxy {
|
|
|
63
66
|
body = JSON.stringify(request.body);
|
|
64
67
|
}
|
|
65
68
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
66
|
-
|
|
67
|
-
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 }));
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw new Error(`Module ${tag} is not responding`);
|
|
71
|
-
}
|
|
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; });
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
72
|
}
|
|
@@ -7,8 +7,10 @@ export interface Module {
|
|
|
7
7
|
}
|
|
8
8
|
export default class BusinessProxy {
|
|
9
9
|
private modules;
|
|
10
|
+
private onError?;
|
|
10
11
|
setModules(modules: {
|
|
11
12
|
[key: string]: Module;
|
|
12
13
|
}): void;
|
|
14
|
+
setOnError(onError: (error: Error) => Error): void;
|
|
13
15
|
call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response>;
|
|
14
16
|
}
|
package/package.json
CHANGED
|
@@ -12,11 +12,16 @@ 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
16
|
|
|
16
17
|
setModules(modules: {[key:string]: Module}) {
|
|
17
18
|
this.modules = modules
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
setOnError(onError: (error: Error) => Error) {
|
|
22
|
+
this.onError = onError;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
async call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response> {
|
|
21
26
|
let module = this.modules[tag];
|
|
22
27
|
if (!module) throw new Error(`Module ${tag} does not exist`);
|
|
@@ -36,11 +41,8 @@ export default class BusinessProxy
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
} catch (error) { throw new Error(`Module ${tag} is not responding`); }
|
|
44
|
+
return fetch(module.host + endpoint + QueryUtils.map(request.query), {
|
|
45
|
+
...request, method, body: method !== "GET" ? body : undefined, headers
|
|
46
|
+
}).catch((error) => this.onError?.(error) ?? error);
|
|
45
47
|
}
|
|
46
48
|
}
|