简体   繁体   中英

Error pages in Grails app hosted using IIS 7 / Tomcat connector

I have a Grails application that is running in Tomcat 7 under IIS 7, using the Jakarta Isapi Tomcat connector version 1.2.30 and I'm having trouble getting the error handling to behave how I'd like. The Tomcat connector is configured in uriworkermap.properties to forward all requests below the application's URL to Tomcat:

/OrderSubmission/* = worker1

The Grails application has its own custom error pages which work fine when the application is running on a development machine without IIS / the Tomcat connector, but when on the server, if custom error pages are switched on in IIS, these always override the ones in the Grails application. This means that where I have a specific page to handle a certain exception type, eg in UrlMappings.groovy :

"500"(controller: 'error', action: 'itemNotFound', exception: ItemNotFoundException)

...I'm instead seeing the static 500 error page that I've pointed IIS at.

If I instead turn on detailed errors in IIS I get the correct error pages through from my Grails application - however, if a request is made for a URL outside of the application's context, I then see the detailed IIS 404 page, which is unacceptable. If I change the Tomcat connector's uriworkermap.properties to include everything from the root downwards then I instead see a default Tomcat 404 error page. I've tried getting the Tomcat connector to default to custom pages by setting the error_page option in isapi_redirect.properties to point to my IIS static custom pages like so:

error_page=/%d.htm

...but this doesn't work, and I can't find any example of using this setting anywhere.

What I need to happen is for the custom Grails error pages to be shown - unless the URL being requested is outside the application or the application is down, at which point I need custom static error pages to be shown.

Has anyone managed to achieve this?

TIA

I ended up making my error page controller methods return a status of 200 (OK), unless dealing with an AJAX request:

class ErrorController {
    def pageNotFound() {
        if (!request.xhr){
            response.status = 200
        }
    }
}

IIS is set to 'Custom error pages'.

This prevents IIS stepping in and providing the custom static pages that I provide, unless the requested URL is outside the scope of the Grails application.

The error status is retained for AJAX requests in order to allow the caller to properly deal with the result.

I'm unsure whether it's satisfactory practice to return 200 from the application on error, particularly with regard to search engines - however it seems that even without this change, when an error occurs and the response is ultimately returned to the browser from IIS it has a status of 200, according to Fiddler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM