handleRequest method
Implementation
Future<void> handleRequest(HttpRequest httpReq) async {
// An adapter must not add or modify the `Transfer-Encoding` parameter, but
// the Dart SDK sets it by default. Set this before we fill in
// [response.headers] so that the user or Shelf can explicitly override it if
// necessary.
httpReq.response.headers.chunkedTransferEncoding = false;
httpReq.response.headers.clear();
final request = Request.from(httpReq);
final response = Response.create();
late PharaohError requestError;
try {
final result = await resolveAndExecuteHandlers(request, response);
return forward(httpReq, result.res);
} catch (error, trace) {
requestError = (exception: error, trace: trace);
}
if (_onErrorCb == null) {
return forward(
httpReq,
response.json(
{
'error': requestError.exception.toString(),
'trace': requestError.trace.toString()
},
statusCode: HttpStatus.internalServerError,
),
);
}
final result = await _onErrorCb!.call(requestError, request, response);
return forward(httpReq, result);
}