-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Better Result error handling #6153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Result error handling #6153
Conversation
|
Cc @bbarkley. |
|
Thanks for tackling this! In our case the most important concern is being able to differentiate between an Exception we've already seen in the filter chain vs one that has been thrown elsewhere that we're not aware of. In the filter chain we can notice failed Futures and have additional context such as the total processing time before failure and additional metadata on the request that upstream filters may have had. I assume that the Based on the diff it looks like looking for |
|
Hi @bbarkley. Thanks for your feedback. I agree that it makes sense for Play to have its own exceptions instead of throwing vanilla RuntimeExceptions. It should be pretty easy to replace the RuntimeExceptions with a bit of grepping. I think Play throws a quite few IllegalArgumentExceptions, IllegalStateExceptions and other standard Java exceptions. Are they a problem for your error handling code too? |
| } | ||
|
|
||
| /** | ||
| * This method is no longer invoked by Play; override the version with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea to backport some/all of this to 2.5.x/2.4.x? We can't just break existing code there so I'm not sure this is going to be the right approach.
An alternative might be to add a statusCode field to UsefulException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we backport, I was thinking of leaving the onServerError method the same. So the backported versions would get 90% of the changes, but the interface would remain the same. I would hack the one place where we need a non-500 server error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. It's definitely the right API to have the status code in the method call. We can address the hack when we do the backport. And I'm also reconsidering whether we need onDevServerError and onProdServerError (see the discussion on #6116).
|
Regarding the exceptions - if Play is internally throwing What do you think about adding a new API to the error handler trait - |
|
Thinking about the future API for trait HttpErrorHandler {
def onError(request: RequestHeader, error: HttpError): Future[Result]
}Where the We can keep some of the utility methods in |
6fffb40 to
29c6b9a
Compare
|
OK, after the discussion on this issue and some more offline discussion with others I realise that there are still lots of questions about how to do error handling in Play. I think it was premature of me to change the |
| } | ||
|
|
||
| /** Error handling to use during execution of a handler (e.g. an action) */ | ||
| private def handleHandlerError(tryApp: Try[Application], rh: RequestHeader, t: Throwable): Future[Result] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this method?
Fixes playframework#6099. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see playframework#6098, playframework#6099).
29c6b9a to
87ec67a
Compare
|
Thanks for the feedback. I've updated this PR now. |
|
@gmethvin, if you're happy with the changes I've made would you mind merging this PR? Thanks! |
|
@richdougherty Since there are some conflicts, would you mind submitting additional PRs for the backports? Feel free to merge them yourself if there are no major issues. |
|
OK, I'll handle the backports. Thanks for merging. :) |
Fixes #6099. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see #6098, #6099).
Fixes playframework#6099. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see playframework#6098, playframework#6099).
This is a backport of playframework#6153. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see playframework#6098, playframework#6099).
This is a backport of playframework#6153. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see playframework#6098, playframework#6099).
This is a backport of #6153. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see #6098, #6099).
This is a backport of playframework#6153. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see playframework#6098, playframework#6099).
* Better Result error handling This is a backport of #6153. When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error handling was done with custom error handling code for the server. This pull request changes the server behavior to use the application's HttpErrorHandler to generate the error result instead of generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see #6098, #6099). * Skip slow failing Akka tests * Update MIMA filters
Fixes #6099.
When the backend server (Netty, Akka HTTP) discovers an error in a result (e.g. invalid headers) the server needs to abort processing the result and send an error result to the user. Previously, this error
handling was done with custom error handling code for the server.
This pull request changes the server behavior to use the application's
HttpErrorHandlerto generate the error result instead of the server generating a custom error response. Using the existing error handler makes the error handling more standardized. It also means that the application will be notified when an error occurs during result generation, which will make it easier to track errors that occur in Play applications (see #6098, #6099).This pull request changes the signature of
HttpErrorHandler'sonServerErrormethod to take a status code parameter. Previously the method always assumed a status code of 500. Now, the method takes astatus code parameter so that it can support additional status codes such as 505, which is needed by this pull request.
Play's error handling code now calls the new method with the status code. The old method is deprecated and no longer called. User code will need to upgrade. This is documented in the Play 2.6 migration documentation.