Exception-handling and default error page

2,707 views
Skip to first unread message

Brandon@MediciGroup

unread,
May 12, 2011, 9:06:01 AM5/12/11
to play-framework
Does anyone know if/how Play supports exception-handling (outside of
the normal try/catch scheme) and default error pages???

For example, in a typical JEE app's web.xml I can have the following:
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>

And in a Spring app I can have this:
@Controller
public class ErrorController implements HandlerExceptionResolver {

@Override
public ModelAndView resolveException( HttpServletRequest
request, Exception exception, ...) {

LOGGER.warn( "ERROR!" + exception );

return new ModleAndView( "generalErrorPage" );
}
}



-----


Can Play be configured to route all unhandled-exceptions to specific
pages/handlers???


Pascal Voitot Dev

unread,
May 12, 2011, 9:16:26 AM5/12/11
to play-fr...@googlegroups.com
In your app/views/errors, you have some default HTML error pages corresponding to the HTTP error codes.
In the controller, you have functions such as error(), forbidden(), notFound() which respond with the expected HTTP error and uses the right HTML page from app/views/errors...

Is it what you mean?

Pascal



--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Gaëtan Renaudeau

unread,
May 12, 2011, 9:30:15 AM5/12/11
to play-fr...@googlegroups.com
Play use http code errors.

If your code throwing an error during a http request, the server will (most of time) return a 500 http code error (if you don't catch exceptions).
If you want to catch exception or handle security, you have some useful functions like forbidden() , notFound(), notFoundIfNull(anObject), ...

You can customize errors pages depending of the http code error (404, 500, 403, ...) by editing app/views/errors/{code}.html files where {code} is you http code.

If you are using other format than html (like xml, json) you can have 404.json , 404.xml, etc...

2011/5/12 Brandon@MediciGroup <bra...@thegreshams.net>
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
---------------------------------------------------
site professionnel: http://pro.grenlibre.fr
blog: http://blog.grenlibre.fr
twitter: http://twitter.com/grenlibre
IM: grena...@gmail.com

Brandon@MediciGroup

unread,
May 14, 2011, 11:15:27 AM5/14/11
to play-framework
Yes, that is exactly what I was looking for -- thanks to both of you
for pointing this out to me!
In this specific-case, I thought I was going to have to provide my own
error-pages (for uncaught errors) but was pleasantly surprised to see
that I only had to modify 404 and 500 to inherit my template.

Nice.
:)





On May 12, 7:16 am, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:

Thijs Rovers

unread,
Jun 30, 2011, 11:33:06 AM6/30/11
to play-framework
Could someone tell me how to make play use my 404.xml and 500.xml when
using the notFound(), error(), etc.. functions? It seems to only
pickup the 404.html and 500.html. I can put XML data in these html
templates, but then the Content-Type of the response is still text/
html.

I tried:

reponse.contentType = "text/xml"
notFound()

But that didn't work.

Help is much appreciated.
Thanks.

On May 12, 3:30 pm, Gaëtan Renaudeau <renaudeau.gae...@gmail.com>
wrote:
> Play use http code errors.
>
> If your code throwing an error during a http request, the server will (most
> of time) return a 500 http code error (if you don't catch exceptions).
> If you want to catch exception or handle security, you have some useful
> functions like forbidden() , notFound(), notFoundIfNull(anObject), ...
>
> You can customize errors pages depending of the http code error (404, 500,
> 403, ...) by editing app/views/errors/{code}.html files where {code} is you
> http code.
>
> If you are using other format than html (like xml, json) you can have
> 404.json , 404.xml, etc...
>
> 2011/5/12 Brandon@MediciGroup <bran...@thegreshams.net>
> IM: grenaud...@gmail.com
Reply all
Reply to author
Forward
0 new messages