UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.WsProxy = 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 WsProxy {
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 => {
15 this.handleError(exceptionsHandler, args, error);
16 return rxjs_1.EMPTY;
17 }));
18 }
19 catch (error) {
20 this.handleError(exceptionsHandler, args, error);
21 }
22 };
23 }
24 handleError(exceptionsHandler, args, error) {
25 const host = new execution_context_host_1.ExecutionContextHost(args);
26 host.setType('ws');
27 exceptionsHandler.handle(error, host);
28 }
29}
30exports.WsProxy = WsProxy;