When i try to implements ErrorDecoder
to decode the feign exception, i found the stream in response.body()
is closed, so when i try to read the stream and trans to string, it throw java.io.IOException: stream is closed
. It's really confused because before the decoder, i didn't do anything to closed the stream advanced.
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));
}
}