开发者

Can Grails exceptionHandler support the following Error Handling Flow

开发者 https://www.devze.com 2022-12-15 21:59 出处:网络
In my rails app that I am porting to grails whenever an unexpected error occurs I intercept the error automatically and display a form to the user informing them that an err开发者_开发问答or has occur

In my rails app that I am porting to grails whenever an unexpected error occurs I intercept the error automatically and display a form to the user informing them that an err开发者_开发问答or has occured and asking them for further information. Meanwhile, as the form is rendered I write the stack trace and other information about who was logged in to a database table. Then if the form is submitted I add that information to the error report.

I cannot tell from the exceptionHandler documentation and BootStrap examples whether that will allow me to grab all the information including various session and request parameters and then stuff them into a database and then post a form.

Any thoughts?


You can use a controller to handle exceptions instead of directly going to error.gsp by changing the '500' code mapping in grails-app/conf/UrlMappings.groovy from

"500"(view:'/error')

to

"500"(controller: 'errors', action: 'error')

Run 'grails create-controller errors' and add the 'error' action:

class ErrorsController {

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

Since you're now in a controller you can access the request, etc. and do whatever database or other post-handling work you like.

0

精彩评论

暂无评论...
验证码 换一张
取 消