UNPKG

1.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RpcProxy = void 0;
4const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5const execution_context_host_1 = require("@nestjs/core/helpers/execution-context-host");
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 !this.isObservable(result)
13 ? result
14 : result.pipe(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 isObservable(result) {
27 return result && shared_utils_1.isFunction(result.subscribe);
28 }
29}
30exports.RpcProxy = RpcProxy;