Resteasy 错误响应主体不可访问

Resteasy error response body is unreachable

我正在使用带有 RestEasy 的 Quarkus 框架进行 REST 通信。 当响应代码为 200 等时,一切都很好。当客户端收到错误代码时,例如400 错误请求 resteasy returns WebApplicationException 并且我无法访问响应主体。

MyService.java

@Path("/")
@RegisterRestClient
@RegisterProvider(value = ClientLoggingFilter.class, priority = 100)
public interface MyService {

    @POST
    @Path("/foo")
    @Consumes(MediaType.APPLICATION_JSON)
    MyRespnse create(MyRequest request);

我一直在尝试从 WebApplicationException 中读取实体,但实体始终为空。在 Postman 服务中 returns body like:

{
   "error" : {
      "id" : "id does not exist"
      }
}

调查http://download.eclipse.org/microprofile/microprofile-rest-client-1.0/apidocs/org/eclipse/microprofile/rest/client/ext/ResponseExceptionMapper.html

@Provider
public class CustomResponseExceptionMapper implements ResponseExceptionMapper<RuntimeException> {
    public CustomResponseExceptionMapper () {
    }

    public boolean handles(int statusCode, MultivaluedMap<String, Object> headers) {

    }

    public CusomExceptionMapper toThrowable(Response response) {
        try {
            String responseString = (String)response.readEntity(String.class);
         ............
        }
    }
}

或者

    public class CustomExceptionMapper
            implements ResponseExceptionMapper<Throwable> {
}

注册 ResponseExceptionMapper 提供程序:

@Path("/xyz")
@RegisterProvider(CustomResponseExceptionMapper.class)
@RegisterRestClient
@Timeout