泽西岛:处理从已映射的异常创建的响应时发生错误 [英] Jersey: Error occurred when processing a response created from an already mapped exception

查看:443
本文介绍了泽西岛:处理从已映射的异常创建的响应时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加自定义异常映射器,但是出现以下错误:

I am trying to add a custom exception mapper, but am getting the following error:

Error occurred when processing a response created from an already mapped exception.

我正在使用Dropwizard,Jersey和Kotlin.

I am using Dropwizard, Jersey, and Kotlin.

推荐答案

问题是在您的应用程序中注册的同一异常有多个ExceptionMappers.要解决此问题,请确保每个Exception类只有一个ExceptionMapper.

The issue is that there are multiple ExceptionMappers for the same exception registered with your application. To fix the issue, make sure that there is only one ExceptionMapper per Exception class.

请注意,这不会阻止为子类注册异常映射器.例如,应用程序可以为Exception或RuntimeException注册一个包含所有内容的映射器.

Note that this does not prevent registering exception mappers for sub classes. For example, an application can register a catch-all mapper for Exception or RuntimeException.

class UnhandledExceptionMapper : ExceptionMapper<Exception> { ... }

并注册更多特定的映射器.

And also register more specific mappers.

class InvalidSearchExceptionMapper : ExceptionMapper<InvalidSearchException> { ... }

不正确:同一类有多个ExceptionMappers

class UnhandledExceptionMapper : ExceptionMapper<Exception> { ... }

这将导致问题中描述的错误.

This will cause the error described in the question.

class OtherUnhandledExceptionMapper : ExceptionMapper<Exception> { ... }

这篇关于泽西岛:处理从已映射的异常创建的响应时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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