openapi-generator
openapi-generator copied to clipboard
[JAVA][RESTTEMPLATE-JAKARTA] - Possibility to retrieve the ResponseEntity object overriding the errorHandler of RestTemplate
I would using my withHttpInfo(...) method generate from my client interface but not work because a RestClientException is throwed when i receive a 404 for example. I have override the Error because i want manage ResponseEntity myself
restTemplate.setErrorHandler(new MyErrorResponseHandler());
var myClient = new ApiClient(restTemplate);
//MyHandler
@Slf4j
public class MyErrorResponseHandler implements ResponseErrorHandler {
@Override
public boolean hasError(@NonNull ClientHttpResponse response) throws IOException {
log.warn("Error response received from My API: {}", response.getStatusCode().value());
return false;
}
@Override
public void handleError(@NonNull ClientHttpResponse response) throws IOException {
// Do nothing
}
}
but in the ApiClient, as you can see, a RestClientException it's throwed if the error isn't 2xx (if the resttemplate's error handler had not managed the exception).
I can't override the ApiClient and i can't catch the http status exception everytime i call an API. I need the ResponseEntity object to do the business logic over here.
Describe the solution you'd like
I want manage the ResponseEntity directly instead a RestClientException
There is an issue already opened for this issues-5397