在Grails 2.2.4最佳实践中使用ExceptionMapper在Grails控制器中进行异常处理 [英] Exception handling in Grails controllers with ExceptionMapper in Grails 2.2.4 best practice

查看:291
本文介绍了在Grails 2.2.4最佳实践中使用ExceptionMapper在Grails控制器中进行异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Grails 2.2.4中使用此处报告的方案处理异常:

While handling exception in Grails 2.2.4 with the scheme reported here:

Grails控制器中的异常处理

    class ErrorController {
      def index() {

        def exception = request.exception.cause
        def message = ExceptionMapper.mapException(exception)
        def status = message.status

        response.status = status
        render(view: "/error", model: [status: status, exception: exception])
      }
   }

引发异常:

groovy.lang.MissingPropertyException: No such property: ExceptionMapper for class: ErrorController

一般处理控制器异常工作?

How does the grails mechanism for general handling of controller exceptions works?

建议的代码是Grails中的最佳实践/推荐方法。

The code proposed is a best practice/recommended way in Grails?

推荐答案

您从另一个问题中复制了一些代码,但它使用的不是Groovy或Grails的一部分的 ExceptionMapper 类(如果您需要导入语句),并且没有在答案中定义。我不知道它是什么,但这样的东西应该工作:

You copied some code from another question, but it uses an ExceptionMapper class that isn't part of Groovy or Grails (and if it were you'd need an import statement), and isn't defined in the answer. I'm not sure what it does, but something like this should work:

def exception = request.exception.cause
response.status = 500
render(view: "/error", model: [exception: exception])

这篇关于在Grails 2.2.4最佳实践中使用ExceptionMapper在Grails控制器中进行异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆