У меня есть ресурс, который вызывает другую конечную точку REST через RestEasy
Если этот вызов не удался (т. Е. Код состояния ответа не был 2xx), я хотел бы вернуть пользовательский ответ об ошибке.
Теперь у меня есть Перехватчик:
@Provider
public class AdapterInterceptor implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
if (responseContext.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
log.error("Error calling adapter. Response Status '{}' Response Body '{}'", responseContext.getStatus(), responseContext.getEntity());
throw new AdapterException(responseContext);
}
}
}
и ExceptionMapper
@Provider
public class AdapterExceptionMapper implements ExceptionMapper<AdapterException> {
@Override
public Response toResponse(AdapterException exception) {
return Response
.status(Response.Status.BAD_REQUEST)
.entity("custom error response")
.build();
}
}
Мой ресурс:
@Path("/test")
public class FrontendResource {
private SchemeAdapterService schemeAdapterService;
public FrontendResource() throws URISyntaxException {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(new URI("http://localhost:8080/mock-adapter"));
schemeAdapterService = target.proxy(SchemeAdapterService.class);
}
@Path("/hello")
@POST
public Response test(@Valid Data data) {
PreCheckinResponse preCheckinResponse = schemeAdapterService.callTest(data);
return Response.ok(preCheckinResponse).build();
}
}
Перехватчик запускается правильно и выдает исключение AdapterException,Однако AdapterException (RuntimeException) никогда не отображается в AdapterExceptionMapper, и я получаю org.jboss.resteasy.spi.UnhandledException
.
Если я выбрасываю исключение из Resource напрямую, ExceptionMapper запускается правильно.От Перехватчика это не похоже на работу.Как мне решить эту проблему?