public class DefaultHttpErrorHandler extends java.lang.Object implements HttpErrorHandler
This class is intended to be extended to allow reusing Play's default error handling functionality. The "play.editor" configuration setting is used here to give a link back to the source code when set and development mode is on.
Constructor and Description |
---|
DefaultHttpErrorHandler(com.typesafe.config.Config config,
Environment environment,
play.api.OptionalSourceMapper sourceMapper,
javax.inject.Provider<play.api.routing.Router> routes) |
Modifier and Type | Method and Description |
---|---|
protected void |
logServerError(Http.RequestHeader request,
play.api.UsefulException usefulException)
Responsible for logging server errors.
|
protected java.util.concurrent.CompletionStage<Result> |
onBadRequest(Http.RequestHeader request,
java.lang.String message)
Invoked when a client makes a bad request.
|
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.
|
protected java.util.concurrent.CompletionStage<Result> |
onDevServerError(Http.RequestHeader request,
play.api.UsefulException exception)
Invoked in dev mode when a server error occurs.
|
protected java.util.concurrent.CompletionStage<Result> |
onForbidden(Http.RequestHeader request,
java.lang.String message)
Invoked when a client makes a request that was forbidden.
|
protected java.util.concurrent.CompletionStage<Result> |
onNotFound(Http.RequestHeader request,
java.lang.String message)
Invoked when a handler or resource is not found.
|
protected java.util.concurrent.CompletionStage<Result> |
onOtherClientError(Http.RequestHeader request,
int statusCode,
java.lang.String message)
Invoked when a client error occurs, that is, an error in the 4xx series, which is not handled
by any of the other methods in this class already.
|
protected java.util.concurrent.CompletionStage<Result> |
onProdServerError(Http.RequestHeader request,
play.api.UsefulException exception)
Invoked in prod mode when a server error occurs.
|
java.util.concurrent.CompletionStage<Result> |
onServerError(Http.RequestHeader request,
java.lang.Throwable exception)
Invoked 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 DefaultHttpErrorHandler(com.typesafe.config.Config config, Environment environment, play.api.OptionalSourceMapper sourceMapper, javax.inject.Provider<play.api.routing.Router> routes)
public java.util.concurrent.CompletionStage<Result> onClientError(Http.RequestHeader request, int statusCode, java.lang.String message)
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.protected java.util.concurrent.CompletionStage<Result> onBadRequest(Http.RequestHeader request, java.lang.String message)
Returns Results.badRequest (400) with the included template from views.html.defaultpages.badRequest
as the content.
request
- The request that was bad.message
- The error message.protected java.util.concurrent.CompletionStage<Result> onForbidden(Http.RequestHeader request, java.lang.String message)
Returns Results.forbidden (401) with the included template from views.html.defaultpages.unauthorized
as the content.
request
- The forbidden request.message
- The error message.protected java.util.concurrent.CompletionStage<Result> onNotFound(Http.RequestHeader request, java.lang.String message)
If the environment's mode is production, then returns Results.notFound (404) with the included template from `views.html.defaultpages.notFound` as the content.
Otherwise, Results.notFound (404) is rendered with views.html.defaultpages.devNotFound
template.
request
- The request that no handler was found to handle.message
- A message, which is not used by the default implementation.protected java.util.concurrent.CompletionStage<Result> onOtherClientError(Http.RequestHeader request, int statusCode, java.lang.String message)
views.html.defaultpages.badRequest
template with the given status.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)
By default, the implementation of this method delegates to [[onProdServerError()]] when in prod mode, and [[onDevServerError()]] in dev mode. It is recommended, if you want Play's debug info on the error page in dev mode, that you override [[onProdServerError()]] instead of this method.
onServerError
in interface HttpErrorHandler
request
- The request that triggered the server error.exception
- The server error.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 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 java.util.concurrent.CompletionStage<Result> onDevServerError(Http.RequestHeader request, play.api.UsefulException exception)
The base implementation returns Results.internalServerError
with the content of views.html.defaultpages.devError
.
request
- The request that triggered the error.exception
- The exception.protected java.util.concurrent.CompletionStage<Result> onProdServerError(Http.RequestHeader request, play.api.UsefulException exception)
The base implementation returns Results.internalServerError
with the content of views.html.defaultpages.error
template.
Override this rather than [[onServerError()]] 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.