response.setStatus in routes

39 views
Skip to first unread message

atomi

unread,
Mar 29, 2011, 6:26:39 PM3/29/11
to gae...@googlegroups.com
Can we set status codes in our routes.groovy?

I've been setting status codes in my templates and the routes.groovy just seems like a better place to set them.
ie: response.setStatus(404)

Guillaume Laforge

unread,
Mar 30, 2011, 2:37:21 AM3/30/11
to gae...@googlegroups.com
Hi,

On Wed, Mar 30, 2011 at 00:26, atomi <at...@lavabit.com> wrote:
> Can we set status codes in our routes.groovy?

No, it's not possible.

> I've been setting status codes in my templates and the routes.groovy just
> seems like a better place to set them.
> ie: response.setStatus(404)

For things like error handlers, the recommended way is to follow the
standard error handling approach:
http://code.google.com/appengine/docs/java/config/webxml.html#Error_Handlers

I tried a bit to work on the routes handler to add some default error
handlers, but it didn't really bring much more, some errors are
swallowed by GAE anyway, and there were some issues with the routes'
forward and/or redirect (I don't remember the specifics though). So I
didn't pursue further.

--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

atomi

unread,
Mar 30, 2011, 4:15:48 AM3/30/11
to gae...@googlegroups.com
Thanks for the reply.

I was handling 404 errors using routes.groovy

get "*", forward: "/404.gtpl" // nice and easy
So the 200 status code was expected.

I went ahead and set the error-page element in web.xml as you've suggested.
Interestingly, the status code sent on page not found errors is still 200.
I don't know if this is a Gaelyk issue or GAE.
Not a big deal, but the status code should definitely be 404 here.

Perhaps it's as you say - GAE swallowing errors.
For those nuanced, using response.setStatus(404) in the error template works just fine.



Guillaume Laforge

unread,
Mar 30, 2011, 4:46:05 AM3/30/11
to gae...@googlegroups.com
Thanks for the feedback.
I also encountered some weird behaviour, as you noticed too, with
regards to status code.
That's the reason why I didn't really go further than this.
Also, some errors like 50x are handled only by the GAE system itself,
and you can't even intercept them for showing even a static page :-(
Perhaps I'll revisit the subject at some point, to see if we can
discover some sense out of all this :-)

Guillaume

> --
> You've received this message because you've subscribed to the Gaelyk Google
> Group.
> To send an email to the group, please write to: gae...@googlegroups.com
> To unsuscribe from this group: gaelyk+un...@googlegroups.com
> To show more options: http://groups.google.fr/group/gaelyk?hl=en

Reply all
Reply to author
Forward
0 new messages