1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.WsProxy = 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 WsProxy {
|
8 | create(targetCallback, exceptionsHandler, targetPattern) {
|
9 | return async (...args) => {
|
10 | args = [...args, targetPattern ?? 'unknown'];
|
11 | try {
|
12 | const result = await targetCallback(...args);
|
13 | return !(0, rxjs_1.isObservable)(result)
|
14 | ? result
|
15 | : result.pipe((0, 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 | }
|
31 | exports.WsProxy = WsProxy;
|