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

Make response available on error in rest client #45282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rober710
Copy link
Contributor

Responses cannot be read if the HTTP status is not in the 2xx range and you request that the response is converted to a specific type, like when calling

httpClient.target("https://example.com/endpoint").request(MediaType.APPLICATION_JSON_TYPE).get(MyBean.class);

In this case, an exception is thrown, but it contains a DummyResponse instance that doesn't give access to the Response object.
Being able to read the response from the server in case of error is extremely valuable in some cases, as it may contain useful information about the problem. Most REST APIs return this information as a JSON object that can be parsed, and the contents examined to see custom error status codes or passing the error message to the user, for example.

This PR sets the response in the exception object, without creating a new field for it, as implementing ResteasyReactiveClientProblem should prevent the server from trying to read the response.

@rober710 rober710 force-pushed the rest-client-response branch from b234baa to 4bb672d Compare December 24, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant