Interface ExceptionHandler

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@UnstableApi
@FunctionalInterface
public interface ExceptionHandler
Converts a Throwable to an AggregatedHttpResponse. Use this ExceptionHandler to send a different response depending on the Throwable:

 ExceptionHandler handler = (ctx, cause) -> {
     if (cause instanceof IllegalArgumentException) {
         return AggregatedHttpResponse.of(HttpStatus.BAD_REQUEST);
     }

     // You can return a different response using the path.
     if ("/outage".equals(ctx.path())) {
         return AggregatedHttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR,
                                          MediaType.PLAIN_TEXT, "Oops, something went wrong.");
     }

     // Return null to let ExceptionHandler.ofDefault() convert the exception.
     return null;
 }

 Server.builder().exceptionHandler(handler)...

 
See Also:
ServerBuilder.exceptionHandler(ExceptionHandler)