Search code examples
grailsurl-mappinghttp-response-codes

Grails URLMapping to Response Codes doesn't work if the request is POST


I am a little crazy about this. At first, my mapping is like below

"500"(view:'/error/exception')

But, then we found, if the exception is throw in Spring Security code, the error page is not correct. By looking the source code, I change the mapping from view to action

"500"(controller: "error", action: "exception")

and, in the action I will send a redirect request to another action which will render view. Seems everything work.

However, today I found if the request which cause exception is GET, it works, if it is a POST, then nothing rendered, it just return 404 to browser.

Could anybody tell me how to walkaround it?


Solution

  • Found a walkaround. Config mapping as:

    "500"(view:'/error/exception')
    

    In the view, write an redirect

    <% response.sendRedirect("/xxx/error/exception") %>
    

    Then , render view in the ErrorControl, exception action.

    Waiting for better solution.