I keep encountering this case where I recieve back a poor HTTP response (just like a 400) but cannot consider the HttpEntity within the HttpResponse object. After I step finished the debugger, I can tell the entity has content (length > ) and that i may even consider the content, but all I see is a range of amounts (ASCII codes I suppose?) which is not useful. I'll call EntityUtils.toString() around the entity, however i return the best -- either an IOException, or some type of "object is within an invalid condition" exception. This is actually frustrating! Can there be any method of getting only at that content inside a human-readable form?

Here's my code :

    protected JSONObject makeRequest(HttpRequestBase request) throws ClientProtocolException, IOException, JSONException, WebRequestBadStatusException {

    HttpClient httpclient = new DefaultHttpClient();

    try {
        request.addHeader("Content-Type", "application/json");
        request.addHeader("Authorization", "OAuth " + accessToken);
        request.addHeader("X-PrettyPrint", "1");

        HttpResponse response = httpclient.execute(request);
        int statusCode = response.getStatusLine().getStatusCode();

        if (statusCode < 200 || statusCode >= 300) {
            throw new WebRequestBadStatusException(statusCode);

        HttpEntity entity = response.getEntity();

        if (entity != null) {
            return new JSONObject(EntityUtils.toString(entity));
        } else {
            return null;

    } finally {

See where I toss the exception? What Let me do is suck the content from the HttpEntity and set it within the exception.

You should use blow code to determine entity like a string (in case your request contentType is html or same factor ..)

 String inputLine ;
 BufferedReader in = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
 try {
       while ((inputLine = in.readLine()) != null) {
  } catch (IOException e) {