public class ExceptionHandler extends Object
writeErrorResponse(Throwable, Serializer, HttpServletRequest, HttpServletResponse):
Complete handling of exceptions thrown by the PServiceCallHandler.handleCall(PServiceCall, PService)
method or similar. Calling super on this will fall back to default exception handling, using the methods
below. This will per default serialize PMessage exceptions normally, and just call
HttpServletResponse.sendError(int,String) for all the others using the Throwable.getMessage()
message.
getResponseException(Throwable): Get the response exception given the specific
thrown exception. This method can be used to unwrap wrapped exceptions, or transform non- message
exceptions into providence message exceptions.
statusCodeForException(Throwable): Get the HTTP status code to be used for the
error response. Override to specialize, and call super to get default behavior. The default will
handle PApplicationException errors, and otherwise return 500 Internal Server Error.
| Modifier and Type | Field and Description |
|---|---|
static ExceptionHandler |
INSTANCE |
| Constructor and Description |
|---|
ExceptionHandler() |
| Modifier and Type | Method and Description |
|---|---|
protected Throwable |
getResponseException(Throwable e)
Get the exception to ge handled on failed requests.
|
void |
handleException(Throwable rex,
net.morimekta.providence.serializer.Serializer responseSerializer,
javax.servlet.http.HttpServletRequest httpRequest,
javax.servlet.http.HttpServletResponse httpResponse)
Handle exceptions from the handle method.
|
protected int |
statusCodeForException(Throwable exception)
With default exception handling, this can simply change the status code used
for the response.
|
protected void |
writeErrorResponse(Throwable rex,
net.morimekta.providence.serializer.Serializer responseSerializer,
javax.servlet.http.HttpServletRequest httpRequest,
javax.servlet.http.HttpServletResponse httpResponse)
Write the error response.
|
public static final ExceptionHandler INSTANCE
public void handleException(@Nonnull Throwable rex, @Nonnull net.morimekta.providence.serializer.Serializer responseSerializer, @Nonnull javax.servlet.http.HttpServletRequest httpRequest, @Nonnull javax.servlet.http.HttpServletResponse httpResponse) throws IOException
getResponseException(Throwable). Otherwise override
writeErrorResponse(Throwable, Serializer, HttpServletRequest, HttpServletResponse)
instead.rex - The response exception, which is the thrown exception or one
of it's causes. See getResponseException(Throwable).responseSerializer - The serializer to use to serialize message output.httpRequest - The HTTP request.httpResponse - The HTTP response.IOException - If writing the response failed.protected void writeErrorResponse(@Nonnull Throwable rex, @Nonnull net.morimekta.providence.serializer.Serializer responseSerializer, @Nonnull javax.servlet.http.HttpServletRequest httpRequest, @Nonnull javax.servlet.http.HttpServletResponse httpResponse) throws IOException
rex - The response exception.responseSerializer - The response serializer.httpRequest - The request.httpResponse - The response.IOException - If writing the response failed.@Nonnull protected Throwable getResponseException(Throwable e)
e - The exception seen.Copyright © 2015–2020 morimekta.net. All rights reserved.