泽西岛:处理从已映射的异常创建的响应时发生错误 [英] Jersey: Error occurred when processing a response created from an already mapped exception
问题描述
我正在尝试添加自定义异常映射器,但是出现以下错误:
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屋!