ExceptionHandlerRaw typedef

ExceptionHandlerRaw = Future<void> Function(HttpRequest rawRequest, String requestId, Object exception, StackTrace stackTrace)

Exception handler for low-level situations.

These exception handlers are only used when the Woomera framework is unable to use an ExceptionHandler.

Implementations of this function type are used for setting the Server.exceptionHandlerRaw.

The implementation must produce a HTTP response without the aid of the Woomera Response classes. As always, when producing a response using the standard Dart HttpResponse, the "rawRequest.response" must be closed.

The exception exception can be used to detect certain conditions and customize the message in the response.

In addition to the exception, the stack trace stackTrace can provide additional information about the problem. But exposing internal implementation details in the response is not recommended. The requestId is an internal identifier assigned to the raw request by Woomera, and is used in log messages produced by Woomera.

Example:

Future<void> myLowLevelExceptionHandler(HttpRequest rawRequest,
     String requestId, Object ex, StackTrace st) async {
   _log.severe('[$requestId] raw exception (${ex.runtimeType}): $ex\n$st');

   final resp = rawRequest.response;

   resp
     ..statusCode = HttpStatus.internalServerError
     ..headers.contentType = ContentType.html
     ..write('''<!doctype html>
<html>
<head><title>Error</title></head>
<body>
 <h1>Error</h1>
 <p>Something went wrong.</p>
</body>
</html>
''');

   await resp.close();
 }

Implementation

typedef ExceptionHandlerRaw = Future<void> Function(HttpRequest rawRequest,
    String requestId, Object exception, StackTrace stackTrace);