[#2171] Action context access from error templates for routes-defined 404 actions#1231
Open
sant0s wants to merge 1 commit intoplayframework:masterfrom
Open
[#2171] Action context access from error templates for routes-defined 404 actions#1231sant0s wants to merge 1 commit intoplayframework:masterfrom
sant0s wants to merge 1 commit intoplayframework:masterfrom
Conversation
ef52c60 to
6cf575a
Compare
90af348 to
778c43c
Compare
Contributor
Author
|
@xael-fry For some reason, ticket 2170/PR 1230 went through in Play! 1.5.2, but related ticket 2171/PR 1231 (this one) didn't. I've just rebased this pull request's branch onto the latest master and re-tested successfully i.e. checked that the issues reported in the ticket show up/do not show up before/after this fix is applied. Could this pull request be included in the next Play! release? |
…lable to templates
778c43c to
473f47e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lighthouse ticket
https://play.lighthouseapp.com/projects/57987-play-framework/tickets/2171
Framework version
1.5.3
Platform
Ubuntu 18.04, Oracle JDK 1.8.0_201
Description
For 404 actions declared in the routes file, action context items (e.g. controllers.Secure.Security.isConnected()) are not available to error templates and exceptions are thrown when they try to access them, resulting in HTTP 500 responses instead of HTTP 404 ones.
Without access to the session, HTTP 404 pages become more limited than other pages. This may cause the web app not be consistent across all pages.
Example: all the pages in a web app feature a navbar that displays "log in" if the user is logged out or "log out" if the user is logged in based on controllers.Secure.Security.isConnected(). The navbar may also display links to different web app actions depending on whether the user is logged in or not. All works well while a logged in user navigates across different pages, but as soon as a routes-defined 404 page is accessed, the navbar cannot be displayed like the other pages, cause there's no access to session information.
Actual behaviour reproduction steps
Create a brand new Play! 1.5.3 app
Add the secure module dependency (play -> secure) in conf/dependencies.yml and execute play dependencies
Include the following code in app/views/errors/404.html and app/views/main.html:
* /notfound 404Start the app
Open a browser at the root URL (http://localhost:9000)
The returned page successfully displays isConnected/Connected
Point the browser at http://localhost:9000/notfound
An HTTP 500 is returned and logs show a NPE:
Expected behaviour
Session information should be available everywhere so web apps can be consistent across all pages.
Technical details
In class PlayHandler, the action context is reset in the init method, making it unavailable in templates.