URL mapping to response codes using controllers: no exceptions object in scope

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

URL mapping to response codes using controllers: no exceptions object in scope

Nicolás Dijkstra
Hello, i changed my UrlMappings.groovy file so i can have error codes mapped to an ErrorController. Inside the controller i'm trying to access exceptions object in the same way that default error.gsp does but i get a null pointer exception.

I'm mapping error codes to a controller so i can use withFormat and render the error description in html or json, depending on the request format.

Any kind of help will be appreciated.

Thanks

--
Nicolás
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping to response codes using controllers: no exceptions object in scope

cazacugmihai
Use something like this in your controller:

def someMethod = {
        def exception = request.exception
}
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping to response codes using controllers: no exceptions object in scope

Nicolás Dijkstra
Hi, thanks for your reply.

I tried your suggestion but request.exception seems to be null though

Any other ideas?

Thanks

On Fri, Jan 22, 2010 at 6:07 PM, Mihai Cazacu <[hidden email]> wrote:
Use something like this in your controller:

def someMethod = {
        def exception = request.exception
}



--
Nicolás Dijkstra
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping to response codes using controllers: no exceptions object in scope

burtbeckwith

In 1.1 you can use

def exception = request['javax.servlet.error.exception']?.cause

and in 1.2 you can use

def exception = request['javax.servlet.error.exception']?.cause?.cause

since there's an extra wrapper exception in 1.2.

Burt

> Hi, thanks for your reply.

>

> I tried your suggestion but request.exception seems to be null though

>

> Any other ideas?

>

> Thanks

>

> On Fri, Jan 22, 2010 at 6:07 PM, Mihai Cazacu <[hidden email]>wrote:

>

> > Use something like this in your controller:

> >

> > def someMethod = {

> > def exception = request.exception

> > }

> >

>

>

>

>

Reply | Threaded
Open this post in threaded view
|

Re: URL mapping to response codes using controllers: no exceptions object in scope

cazacugmihai
Just for testing, write a method that contains this code and see the result(error is in request['javax.servlet.error.exception']?cause...):

[code]
def analyzeRequest = {
    StringWriter w = new StringWriter()
    new MarkupBuilder(w).html {
        head {
            title 'Errors'
        }
        body {
            table(style: 'font-size: 9px', border: 1, cellpadding: 1, cellspacing: 0) {
                tbody {
                    request.attributeNames.each {attrName ->
                        tr {
                            td { yield(attrName)  }
                            td { yield(request[attrName].toString()) }
                        }
                    }
                }
            }
        }
    }

    render w.toString()
}
[/code]