ExceptionHandler typedef

ExceptionHandler = Future<Response> Function(Request request, Object exception, StackTrace stackTrace)

Exception handler for high-level situations.

These high-level situations usually occur because a server exception handler or pipeline exception handler raised an exception.

Implementations of this function type are used for setting the Server.exceptionHandler and ServerPipeline.exceptionHandler.

The implementation must return a Future to a Woomera Response, which should be an error page for the HTTP response.

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 stack trace is optional: sometimes it cannot be provided.

Example:

Future<Response> myExceptionHandler(Request request,
 Object e, StackTrace st) async {
  final r = ResponseBuffered(ContentType.html);
   r.status = HttpStatus.internalServerError;
   r.write('''<!doctype html>
<html>
 <head><title>Error</title></head>
 <body>
    <h1>Error</h1>
    <p>Something went wrong.</p>
 </body>
</html>
''');
   return r;
}

Implementation

typedef ExceptionHandler = Future<Response> Function(
    Request request, Object exception, StackTrace stackTrace);