# All files / core/router router-proxy.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 6/6
100% Lines 12/12

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    1x

    1x

    7x
    2x
    2x

    2x
    2x

    4x
    2x
    2x

    2x
    2x

     import { ExceptionsHandler } from '../exceptions/exceptions-handler';
    import { ExecutionContextHost } from '../helpers/execution-context.host';

    export type RouterProxyCallback = (req?, res?, next?) => void;

    export class RouterProxy {
      public createProxy(
        targetCallback: RouterProxyCallback,
        exceptionsHandler: ExceptionsHandler,
      ) {
        return async (req, res, next) => {
          try {
            await targetCallback(req, res, next);
          } catch (e) {
            const host = new ExecutionContextHost([req, res]);
            exceptionsHandler.next(e, host);
          }
        };
      }

      public createExceptionLayerProxy(
        targetCallback: (err, req, res, next) => void,
        exceptionsHandler: ExceptionsHandler,
      ) {
        return async (err, req, res, next) => {
          try {
            await targetCallback(err, req, res, next);
          } catch (e) {
            const host = new ExecutionContextHost([req, res]);
            exceptionsHandler.next(e, host);
          }
        };
      }
    }