UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.WsProxy = 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 rxjs_1 = require("rxjs");
7const operators_1 = require("rxjs/operators");
8class 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}
34exports.WsProxy = WsProxy;