当我尝试实现ErrorDecoder
对 feign 异常进行解码时,我发现输入的流response.body()
已关闭,因此当我尝试读取流并转换为字符串时,它会抛出java.io.IOException: stream is closed
. 这真的很困惑,因为在解码器之前,我没有做任何事情来关闭高级流。
public class FeignClientErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
log.info("feign client response: {}", response);
String body = null;
try {
body = Util.toString(response.body().asReader(Charset.defaultCharset()));
} catch (IOException e) {
log.error("feign.IOException", e);
}
return new ServiceException(MessageCode.builder(ExceptionCodeEnum.ERROR));
}
}