我的实施
ExceptionMapper
如下所示:
@Provider
public class CaptureUnhandledExceptions implements ExceptionMapper<Throwable>
{
private static final Logger LOGGER = LogFactory.getLogger(CaptureUnhandledExceptions.class);
@Override
public Response toResponse(Throwable exception)
{
LOGGER.error("Unhandled exception", exception);
ErrorMessage em = new ErrorMessage(50099, ExceptionUtils.getRootCause(exception).getMessage(),
exception.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(em).build();
}
}
JSON
但它引发了以下异常
Can not deserialize value of type com.abccompany.model.ConnectionEndpoint$Binding from String "RandomValue: value not one of declared Enum instance names: [POST, REDIRECT]
at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@3fce79f3; line: 16, column: 28] (through reference chain: com.abccompany.model.SpConnection["connection"]->com.abccompany.model.Connection["connectionendpoints"]->java.util.ArrayList[0]->com.abccompany.model.ConnectionEndpoint["endpointbinding"])
我错过了什么?我必须在中注册我的提供商吗
ResourceConfig
?
在应用程序的ResourceConfig中
this.register(com.abccompany.utils.CaptureUnhandledExceptions.class);