artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

Cannot get the response body for non-2xx responses #92

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.5.0-beta)?

1.7.0-beta

Java environment (e.g. Java 6, Android 2.3, App Engine)?

Java 6

Describe the problem.

With the deprecation of the HttpResponseException.getResponse() which I guess 
is because of the improves error message code there is now no way to get the 
response body from a request that didn't return a 2xx response.

My current use case is that I'm using google http client to write some 
functional tests against a http api and have need to check that certain error 
cases return informative error messages. I am unable to do this now because 
there is no direct way to get the response body any more.

How would you expect it to be fixed?

Add a getContentAsString() method to HttpResponseException which returns the 
cached response body content as computed in computeMessageWithContent(). This 
will allow me to get hold of the content when the exception is thrown and check 
it for correctness in my tests.

Original issue reported on code.google.com by matt.nat...@gmail.com on 23 Apr 2012 at 8:52

GoogleCodeExporter commented 9 years ago
Oops, obviously you can always setThrowExceptionOnExecuteError(false) and 
handle the response yourself, or set a HttpUnsuccessfulResponseHandler on the 
request and deal with it that way

Original comment by matt.nat...@gmail.com on 23 Apr 2012 at 9:29

GoogleCodeExporter commented 9 years ago
Yes you can use setThrowExceptionOnExecuteError or 
HttpUnsuccessfulResponseHandler.

Marking the bug as closed.

Original comment by rmis...@google.com on 23 Apr 2012 at 11:14