I have a use case running tests where the server I hit responds with an XML body instead of the expected type I'm unmarshalling to when there is an error. It would be convenient if I could see what the response body was to determine what the true cause of failure was, instead of just seeing a generic "Error while extracting response".

This change could be easily done by instead of throwing a RestClientException, throw something that contains the response in the exception. (Anything extending RestClientResponseException) That way in my test framework code, I can try catch and rethrow the exception exposing the response body.

I see that a similar change was done for the case where the converter is not found - could we do the same for my use case too? https://github.com/spring-projects/spring-framework/commit/aa97563853535d5fea773e18980a8ac964d3e618

Example failed test cause in my framework: (redacted some class names)

Caused by: org.springframework.web.client.RestClientException: Error while extracting response for type [class] and content type [application/xml;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not unmarshal to [class]: null; nested exception is javax.xml.bind.UnmarshalException
 - with linked exception:
[Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor with default root element Application_Error was not found in the project]

when the real response was

Content:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><Application_Error Type="Error"><Message>Request timed out.</Message></Application_Error>

Thanks!

Comment From: epiwd

any update on this?

Comment From: sdeleuze

Any thought on this one @rstoyanchev?

Comment From: rstoyanchev

The challenge is when an HttpMessageNotReadableException is raised it means some sort of parse error occurred which could occur after some part of the content has been consumed, and we can't read the content a second time.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.