I have a feign client service built like this :
Feign.Builder builder = Feign.builder()
.contract(new SpringMvcContract())
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.errorDecoder(new FeignClientErrorHandler())
return builder.target(targetClass, url);
I have the FeignClientErrorDecoder
which looks like this :
public class FeignClientErrorDecoder implements ErrorDecoder {
private static final ObjectMapper MAPPER = new ObjectMapper().registerModule(new JavaTimeModule());
@Override
public Exception decode(final String methodKey,
final Response response) {
try {
byte[] body = Util.toByteArray(response.body().asInputStream());
ApiError apiError = MAPPER.readValue(body, ApiError.class);
return ExceptionFactory.createFrom(apiError);
} catch (IOException | ApiErrorException e) {
return new TechnicalClientException("Could not extract error payload.", e);
}
}
}
No matter which reading input stream solution I choose, I always get a stream is closed
error.
What am I missing ? Who is closing it ? Any workaround ?
Complete code here :
https://github.com/louisamoros/feign-error-code
You can run mvn clean install
and see that 1 test is in error.