1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.RpcProxy = void 0;
|
4 | const execution_context_host_1 = require("@nestjs/core/helpers/execution-context-host");
|
5 | const rxjs_1 = require("rxjs");
|
6 | const operators_1 = require("rxjs/operators");
|
7 | class RpcProxy {
|
8 | create(targetCallback, exceptionsHandler) {
|
9 | return async (...args) => {
|
10 | try {
|
11 | const result = await targetCallback(...args);
|
12 | return !(0, rxjs_1.isObservable)(result)
|
13 | ? result
|
14 | : result.pipe((0, operators_1.catchError)(error => this.handleError(exceptionsHandler, args, error)));
|
15 | }
|
16 | catch (error) {
|
17 | return this.handleError(exceptionsHandler, args, error);
|
18 | }
|
19 | };
|
20 | }
|
21 | handleError(exceptionsHandler, args, error) {
|
22 | const host = new execution_context_host_1.ExecutionContextHost(args);
|
23 | host.setType('rpc');
|
24 | return exceptionsHandler.handle(error, host);
|
25 | }
|
26 | }
|
27 | exports.RpcProxy = RpcProxy;
|