Grails自定义封送处理程序异常处理
我正在为Grails 2.3.7中编写的RESTful应用程序编写一个自定义封送拆收器,contians服务方法调用:Grails自定义封送处理程序异常处理,grails,Grails,我正在为Grails 2.3.7中编写的RESTful应用程序编写一个自定义封送拆收器,contians服务方法调用: class CommentMarshaller implements MarshallerRegistrar { @Autowired RatingService ratingService @Override void register() { JSON.registerObjectMarshaller(Comment) {
class CommentMarshaller implements MarshallerRegistrar {
@Autowired
RatingService ratingService
@Override
void register() {
JSON.registerObjectMarshaller(Comment) { Comment comment ->
def total = ratingService.getSumRating(comment)
if (!total) {
throw new IllegalStateException("to be caught")
}
return [
id: comment.id,
created: comment.created,
text: comment.text,
authorName: comment.author.username,
authorId: comment.author.id,
rating: total
]
}
}
}
我正试图捕获异常,这些异常是在我的ErrorController中从marshaller抛出的:
class UrlMappings {
static mappings = {
"500"(controller: "error", action: "handleError")
}
}
当控制器代码中出现错误时,它可以完美地工作,但当marshaller抛出异常时,Grails会尝试查找error.gsp并在那里呈现stacktrace。
如何将错误从marshaller重定向到ErrorController