registerHandler method

dynamic registerHandler({
  1. String path = "*",
  2. Function? requestHandler,
  3. ResponseProcessor? responseProcessor,
  4. Function? errorFunction,
})

Implementation

registerHandler( {String path = "*",Function? requestHandler,ResponseProcessor? responseProcessor,Function? errorFunction}) async {
  jaguarMux.Route route = jaguarMux.Route.get(path, (context) async {
    try {
      if (requestHandler != null) {
        SimpleWebRR webRR = await _getSimpleWebRR(context);
        webRR = await requestHandler(webRR);
        context.response = await _getResponseFromSimpleWebRR(webRR);
      } else {
        context.response = Response(statusCode: 400);
      }
    } catch (ex,stack) {
      context.response = Response.html(Simplify.getExceptionMessage(ex,stack: stack));
      if (errorFunction != null) {
        dynamic errorResponse =
            errorFunction(Simplify.getExceptionMessage(ex,stack: stack));
        if (errorResponse != null) {
          context.response = Response.html(errorResponse);
        }
      }
    }
  }, responseProcessor: responseProcessor);
  routes.add(route);
}