Reputation:
I'm playing around with error pages per status code and am having troubles rendering views.
I'm using the normal URLMappings strategy for this and using an errors controller to do additional processing and render the view (I'm starting with 500 but will add more obviously):
"500"(controller: 'error', action: 'internalServerError')
In my controller I'm just rendering the views associated with the error:
def internalServerError() {
render view: '/error/internalServerError'
}
The view isn't anything special, just contains a simple message and such. When I plant something in my code that causes an exception, my controller action above does get called but for some reason render doesn't cause the view to render. It basically just eats the exception and from the user perspective it seems like nothing happened.
I've been tinkering with different rendering options and returns but the same thing always happens. Also worth noting that changing URLMappings to:
"500"(view:'/error/internalServerError')
causes the same thing to happen. Am I missing something here?
Upvotes: 0
Views: 2652
Reputation:
Looks like it is something unrelated to Grails rendering or URL mappings. It is happening in some parts of the app and not others so there is a bug. Keeping alive for the URLMappings discussion.
Upvotes: 1
Reputation: 50245
Render the view directly instead of providing the relative path in the action:-
def internalServerError() {
render view: 'internalServerError'
}
with grails-app/views/error/internalServerError.gsp
in place.
UPDATE
Here is how it works:
//UrlMapping:
"500"(controller: 'errors', action: 'internalServerError')
//ErrorsController:
class ErrorsController {
def index() {
response.sendError(500)
}
def internalServerError(){
render view: 'internalServerError'
}
}
//grails-app/views/errors/internalServerError.gsp
This is my customized Internal Server Error.
Try hitting the index
action of the controller.
http://localhost:8080/yourApp/errors
You should see your customized error page.
The same holds good if you are trying to handle Exceptions, like
"500"(controller: 'errors', action: 'internalServerError', exception: Exception)
def index(){
throw new Exception()
}
will yield the same result.
Note:-
You would need to override or remove this default grails provided entry from UrlMapping.groovy
//"500"(view:'/error')
Upvotes: 4