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