Friday, August 7, 2009

Grails : custom error page on any exception

Hi Friends,

To display the custom error page on production instead of any exception that might occur, We can use modify error.gsp file. Error.gsp file is the one which is executed anytime any exception occurs.
As grails enables us to configure the application in development, production and testing environments. We can use the same error.gsp file and render certain gsp as per the current environment.

< html >
< g:if test="${GrailsUtil.isDevelopmentEnv()}" >
< head >
< title >Grails Runtime Exception< /title >...
< /head >< body > ...
...< !-- Default error.gsp body part -- >
< /body >
< /g:if >
< g:else >
< g:render template="/errorPage"/ >
< /g:else >
< /html >

In the above code, in development environment the error.gsp would execute the default code but in any other environment it would render the template "errorPage", which is our custom user friendly errorPage template.

Cheers!
~~Amit Jain~~
amitjain1982@gmail.com

No comments:

Post a Comment