Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
HttpResponseException should have getContent() method #143
From roy.hash...@gmail.com on July 26, 2012 10:58:17
Version of google-http-java-client (e.g. 1.5.0-beta)? 1.10 Java environment (e.g. Java 6, Android 2.3, App Engine)? Any Describe the problem. When this exception is thrown, the only way to get the HttpResponse content is to parse the exception message. The format of the exception message is simple but is not documented.
In my case, I need to catch an HttpResponseException that results from an OAuth2 exchange and examine the JSON returned to determine what happened. I have to extract the JSON from the exception message before applying a JSON parser. If the undocumented format of the exception message changes, my code will also break. How would you expect it to be fixed? This could be fixed simply by documenting the format of the String returned by getMessage() and defining it as part of the API. It would be much better, however, to add a getContent() method that returns only the content. This is the strategy recommended in Effective Java Item 10: Always override toString.