Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Netflix外挂:404上的ErrorDecoder中的响应正文为空_Java_Spring_Netflix Feign - Fatal编程技术网

Java Netflix外挂:404上的ErrorDecoder中的响应正文为空

Java Netflix外挂:404上的ErrorDecoder中的响应正文为空,java,spring,netflix-feign,Java,Spring,Netflix Feign,我已经实现了一个自定义错误解码器: public class WebShopErrorDecoder implements ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { JacksonDecoder jacksonDecoder = new JacksonDecoder(); try { ErrorResource erro

我已经实现了一个自定义错误解码器:

public class WebShopErrorDecoder implements ErrorDecoder {

  @Override
  public Exception decode(String methodKey, Response response) {

    JacksonDecoder jacksonDecoder = new JacksonDecoder();
    try {
        ErrorResource error = (ErrorResource) jacksonDecoder.decode(response, ErrorResource.class);

        return new EShopRequestException(error, HttpStatus.valueOf(response.status()));
    } catch (IOException e) {

        return new EShopRequestException(new ErrorResource("error.internal", "Internal server error"),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
}
我想用这个
WebShopErrorDecoder
ist实现的是转发错误响应。 我的问题是,如果响应状态为404,则ErrorResource
error
为空

例如,如果我将返回的响应状态更改为400,则错误资源包含响应

当通过浏览器直接请求已使用的服务时,我可以看到响应主体的响应状态为404

为什么当服务返回404时,假请求的响应主体是空的? 有没有办法得到反应体

我刚开始与外文合作,所以如果我的问题不清楚,请让我知道,我试图澄清遗漏了什么


提前谢谢

好吧,我刚刚发现为什么响应是空的。这不是假装的错,是我的错

由于我使用了JacksonDecoder,如果响应状态为404,那么由于JacksonDecoder中的以下代码,我将得到一个空响应

..
public Object decode(Response response, Type type) throws IOException {
    if(response.status() == 404) {
        return Util.emptyValueOf(type);
    }
..
我现在做的是使用
responseEntityCoder

public class WebShopErrorDecoder implements ErrorDecoder {

  private final ResponseEntityDecoder decoder;

  public WebShopErrorDecoder(ResponseEntityDecoder decoder) {
    this.decoder = decoder;
  }

  @Override
  public Exception decode(String methodKey, Response response) {
    try {
        ErrorResource error = (ErrorResource) decoder.decode(response, ErrorResource.class);

        return new EShopRequestException(error, HttpStatus.valueOf(response.status()));
    } catch (IOException e) {

        return new EShopRequestException(new ErrorResource("error.internal", "Internal server error"),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
}
现在一切正常:)