I have a filter that does some check and returns false based on that check failure. But, before it returns false it renders error view that should be displayed to user in case of such errors. Instead, a blank page is displayed with error code 404. Note that url contains controller and action that do not exists so normally a 404 would make sense but since i have applied a global filter here which gets called and makes the render call, i am concerned about that render call which didnt materialized.
2 Answers
0
votes
Can you share code ?
I guess you try to render something that does not exist.
Following code works for me
def filters = {
before = { Map model ->
...
render (view: '/access-denied')
return false
}
and it renders access-denied.gsp
Also usually I am not rendering view in this kind of case, Instead I am redirecting it something like following
before = { Map model ->
...
redirect(uri: '/access-denied')
return false
}
0
votes
You can use forward to render a view in a filter. E.g.
all(controller:'*', action:'*') {
before = {
if(requirePost && !"post".equalsIgnoreCase(request.method)) {
response.status = 405
response.setHeader('Access','POST');
forward(controller: 'page', action: 'http405')
return false;
}
}
}
This way the URL does not change.