Reputation: 12338
In the bowels of my grails controllers or services, something is throwing an exception (I assume). The result is the web page just shows "an error has occurred", which is not much help.
The strange thing about grails is it seems to throw no exceptions, so I cant put try/catch and do something like log the error or send an explicit error message with stack trace to the user.
Any ideas how this can be done with grails? When I search, I only find info on displaying validation errors, unfortunately. I am sure there is an easy way!
As I have no idea what kind of exception is actually occurring, or why, I need to catch and display any exception with a stack trace.
Upvotes: 0
Views: 1132
Reputation: 12338
OK, the answer was actually quite easy. You just have to create an error.gsp in the root of your views, with the following code (which will output the except no matter what env is there:
<!DOCTYPE html>
<html>
<head>
<title><g:if env="development">Grails Runtime Exception</g:if><g:else>Error</g:else></title>
<meta name="layout" content="main">
<g:if env="development"><link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css"></g:if>
</head>
<body>
<h2>Time: <g:formatDate format="yyyy-MM-dd hh:mm:ss" date="${new Date()}"/> </h2>
<g:renderException exception="${exception}" />
</body>
</html>
Upvotes: 1