All files / websockets/context ws-proxy.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 3/3
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x     1x         2x 1x 1x   1x 1x          
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context.host';
import { WsExceptionsHandler } from '../exceptions/ws-exceptions-handler';
 
export class WsProxy {
  public create(
    targetCallback: (...args) => Promise<void>,
    exceptionsHandler: WsExceptionsHandler,
  ): (...args) => Promise<void> {
    return async (...args) => {
      try {
        return await targetCallback(...args);
      } catch (e) {
        const host = new ExecutionContextHost(args);
        exceptionsHandler.handle(e, host);
      }
    };
  }
}