-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Include response body in RestTemplate exception when there is no suitable HttpMessageConverter #24964
Comments
This is expected behavior. |
I want keep response body only theres no suitable converter exist case. in this case, response body not read why in message converter check loop execute first not when exeception ariesed while response body stream read. ( like this case.. @Test
public void test(){
try {
Map body = restTemplate.getForObject("https://www.google.com/", Map.class);
}catch (RestClientException e) {
// current status just only throws RestClientException without body end search of for loop. without stream read.
log.info("{}, {}", e.getClass().getCanonicalName(), e.getMessage());
// when modified, developer can check response body
if (e instanceof RestClientResponseException){
log.info("## No Suitable MessageConverter Body ##");
log.info("{}", ((RestClientResponseException) e).getResponseBodyAsString());
}
}
} log..
|
Yes I see now. @poutsma do you think using |
thanks! when detail spec discussion end, like can i create pull request base on that code? |
Yes. |
Yes, I think |
Why not just keep the modification of I have same situation when I got a If needed I can submit a PR to resolve this. |
When RestTemplate receive Response from target server, but there's no body readerble converter, throws RestClientException with only situation describing message.
In this situation, even though communication with the server is normally completed, the content of the received text is lost only because the object conversion of the specified type is impossible.
The results seem unfriendly to developers.
It is extremely natural that Exception is thrown because object conversion is impossible, but preserving the response value so that the developer can confirm that the object was not converted to the intended object because the value was returned in the response is helpful in the development or production stage. I think it need. (Especially production)
sually, if the values of the object conversion failure case are unexpectedly returned in the body, the status code may not 2xx, so an HttpServerErrorResponse or HttpClientErrorException will be thrown, but there is no 100% guarantee that the other server will follow the general status code rules. It may or may not be intentional.
Also, may have misplaced the conversion specification simply by the carelessness of the developer writing the communication code.
Anyway, the important thing is that it's a good idea to provide more effective information for trace exception by providing the full value of the response body returned to the developer.
I searched similar issue on github and stackoverflow, but could not find.
So I modified codes of
HttpMessageConverterExtractor.class
near line 120 as below, and I'd like to hear your opinion.I would appreciate it if you would like to keep the body values or if there is a better way.
thanks.
Current
Suggest
The text was updated successfully, but these errors were encountered: