All files / microservices/context rpc-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 19 201x       1x         2x 1x 1x   1x 1x          
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context.host';
import { Observable } from 'rxjs';
import { RpcExceptionsHandler } from '../exceptions/rpc-exceptions-handler';
 
export class RpcProxy {
  public create(
    targetCallback: (...args) => Promise<Observable<any>>,
    exceptionsHandler: RpcExceptionsHandler,
  ): (...args) => Promise<Observable<any>> {
    return async (...args) => {
      try {
        return await targetCallback(...args);
      } catch (e) {
        const host = new ExecutionContextHost(args);
        return exceptionsHandler.handle(e, host);
      }
    };
  }
}