UNPKG

1.06 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RpcProxy = void 0;
4const execution_context_host_1 = require("@nestjs/core/helpers/execution-context-host");
5const rxjs_1 = require("rxjs");
6const operators_1 = require("rxjs/operators");
7class 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}
27exports.RpcProxy = RpcProxy;