views:

194

answers:

1

Hello I'm trying to implement simple custom error page after any Unhandled Exception being thrown by the Grails code. I've mapped the 500 to my controller:

    "500" (
        controller: "error",
        action:     "serverError"
    )

and handled the exception in the controller:

def serverError = {
    try {
        // first check, if some exception was reported
        if (!request.exception) {
            return
        }

        // send mail with stack trace if requested
        if (shouldSendErrorReports) {
            log.debug "Mail was sent out successfully..."
        }

    } catch (Throwable e) {
        log.error "Error while reporting an error: " + e
    }

    // redirect to error message
    redirect (
        action: "errorMessage"
    )
}
// lines omitted for clarity

"errorMessage" action is just a simple view, rendering GSP page by default with static content -- information and click-to-redirect window. The page has (I hope) correct prolog:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page isErrorPage="true" %>

Now, when testing it locally via NetBeans (Jetty), it all works fine and the errorMessage page is displayed; when deployed to TEST environment (Tomcat6), Tomcat stack-trace is displayed.

How to prevent this Tomcat stack-trace being displayed? I have two thoughts -- first, I'm not really correctly dump-ing (handling?) the Exception, so it bubbles to Tomcat -- second, Tomcat has some configuration value set, so it displays the stack-trace anyway.

Please, if you have any thoughts on this, let me know. Spend some 5 hours figuring this out... :-/

Thank you!

A: 

Hi I use:

 def error = {
        def exception = request['javax.servlet.error.exception']?.cause?.cause
        if(exception){          

        }       
    }
Tom
sorry, that's not it... i can get the exception itself using request.exception, but can't stop it propagating up to tomcat's handler...
mx0r