title: URL connection: how to get body returned with status != 200?
body: <p>I have a webservice returning, sometimes, status 401. 
  It comes with a JSON body, something like:</p>
  
  <pre><code>{"status": { "message" : "Access Denied", "status_code":"401"}}
  </code></pre>
  
  <p>Now, this is the code I'm using to make server requests:</p>
  
  <pre><code>HttpURLConnection conn = null;
  try{
     URL url = new URL(/* url */);
     conn = (HttpURLConnection)url.openConnection(); //this can give 401
     JsonReader reader = new JsonReader(new InputStreamReader(conn.getInputStream()));
  
     JsonObject response = gson.fromJson(reader, JsonObject.class);
     //response handling
  }catch(IOException ex){
         System.out.println(conn.getResponseMessage()); //not working
  }
  </code></pre>
  
  <p>When request fails I'd like to read that json body, however getResponseMessage just gives me a generic "Unauthorized"...so how to retrieve that JSON?</p>