Announcement Announcement Module
Collapse
No announcement yet.
Mapping to response codes doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mapping to response codes doesn't work

    Hi again,

    according to the grails documentation I've got this in my UrlMappings.groovy:

    Code:
    		"403"(controller: "errors", action: "forbidden")
    		"404"(controller: "errors", action: "notFound")
    		"500"(controller: "errors", action: "serverError")
    In my security filter I'm redirecting like this:

    Code:
    redirect(controller: "errors", action: "forbidden")
    However I'm always getting a 404 after the redirect. So I tried adding:

    Code:
    static mappings = {
       "403"(view: "/errors/forbidden")
       "404"(view: "/errors/notFound")
       "500"(view: "/errors/serverError")
    }
    as the redirect points to "/errors/forbidden". However I'm getting a 404 again. In case that ordering matters in some way I added these mappings at the top of the file.

    I ended up with:

    response.sendError(403, "forbidden")

    Which works just fine. But I'm wondering why the other way didn't work. Am I getting something totally wrong or am I just missing a small piece?

    Cheers,
    Thomas

  • #2
    Originally posted by ThomasBecker View Post
    Hi again,

    according to the grails documentation I've got this in my UrlMappings.groovy:

    Code:
    		"403"(controller: "errors", action: "forbidden")
    		"404"(controller: "errors", action: "notFound")
    		"500"(controller: "errors", action: "serverError")
    In my security filter I'm redirecting like this:

    Code:
    redirect(controller: "errors", action: "forbidden")
    However I'm always getting a 404 after the redirect.
    Using redirect(), forward(), or chain() like this requires a reverse URL mapping lookup so that Grails knows what the URL for a given controller action is. An error mapping cannot be queried in the reverse direction, since it doesn't correspond to a URL.

    I can see what you are trying to do, but the standard approaches involve either:
    Code:
    response.sendError(404)
    or

    Code:
    render text: "Page not found", status: 404
    Peter

    Comment


    • #3
      Hi Peter,

      ok. I think I'll leave it at response.sendError as it works well.

      Cheers,
      Thomas

      Comment


      • #4
        What if I want to display error details in the view? Is it possible to pass a model to the error view using sendError?

        Comment

        Working...
        X