Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JAVA][RESTTEMPLATE-JAKARTA] - Possibility to retrieve the ResponseEntity object overriding the errorHandler of RestTemplate #18700

Open
pcomp96 opened this issue May 17, 2024 · 1 comment

Comments

@pcomp96
Copy link

pcomp96 commented May 17, 2024

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).

image

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

@pcomp96
Copy link
Author

pcomp96 commented May 17, 2024

There is an issue already opened for this issues-5397

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant