public class JsonHttpErrorHandler extends java.lang.Object implements HttpErrorHandler
Constructor and Description |
---|
JsonHttpErrorHandler(Environment environment,
play.api.OptionalSourceMapper sourceMapper) |
Modifier and Type | Method and Description |
---|---|
protected com.fasterxml.jackson.databind.JsonNode |
devServerError(Http.RequestHeader request,
play.api.UsefulException exception)
Invoked in dev mode when a server error occurs.
|
protected com.fasterxml.jackson.databind.JsonNode |
formatDevServerErrorException(java.lang.Throwable exception)
Format a
Throwable as a JSON value. |
protected void |
logServerError(Http.RequestHeader request,
play.api.UsefulException usefulException)
Responsible for logging server errors.
|
java.util.concurrent.CompletionStage<Result> |
onClientError(Http.RequestHeader request,
int statusCode,
java.lang.String message)
Invoked when a client error occurs, that is, an error in the 4xx series.
|
java.util.concurrent.CompletionStage<Result> |
onServerError(Http.RequestHeader request,
java.lang.Throwable exception)
Invoked when a server error occurs.
|
protected com.fasterxml.jackson.databind.JsonNode |
prodServerError(Http.RequestHeader request,
play.api.UsefulException exception)
Invoked in prod mode when a server error occurs.
|
protected play.api.UsefulException |
throwableToUsefulException(java.lang.Throwable throwable)
Convert the given exception to an exception that Play can report more information about.
|
@Inject public JsonHttpErrorHandler(Environment environment, play.api.OptionalSourceMapper sourceMapper)
public java.util.concurrent.CompletionStage<Result> onClientError(Http.RequestHeader request, int statusCode, java.lang.String message)
HttpErrorHandler
onClientError
in interface HttpErrorHandler
request
- The request that caused the client error.statusCode
- The error status code. Must be greater or equal to 400, and less than 500.message
- The error message.public java.util.concurrent.CompletionStage<Result> onServerError(Http.RequestHeader request, java.lang.Throwable exception)
HttpErrorHandler
onServerError
in interface HttpErrorHandler
request
- The request that triggered the server error.exception
- The server error.protected final play.api.UsefulException throwableToUsefulException(java.lang.Throwable throwable)
This will generate an id for the exception, and in dev mode, will load the source code for the code that threw the exception, making it possible to report on the location that the exception was thrown from.
protected void logServerError(Http.RequestHeader request, play.api.UsefulException usefulException)
The base implementation uses a SLF4J logger. If a special annotation is desired for internal server errors, you may want to use SLF4J directly with the Marker API to distinguish server errors from application errors.
This can also be overridden to add additional logging information, eg. the id of the authenticated user.
request
- The request that triggered the server error.usefulException
- The server error.protected com.fasterxml.jackson.databind.JsonNode devServerError(Http.RequestHeader request, play.api.UsefulException exception)
request
- The request that triggered the error.exception
- The exception.protected com.fasterxml.jackson.databind.JsonNode formatDevServerErrorException(java.lang.Throwable exception)
Throwable
as a JSON value.
Override this method if you want to change how exceptions are rendered in Dev mode.exception
- an exceptionprotected com.fasterxml.jackson.databind.JsonNode prodServerError(Http.RequestHeader request, play.api.UsefulException exception)
#onServerError(RequestHeader, Throwable)
if you don't want to change Play's debug output when logging errors
in dev mode.request
- The request that triggered the error.exception
- The exception.