public static String getErrorResponse ( HttpURLConnection connection , boolean isZipped ) throws IOException { if ( connection != null ) { InputStream is = null ; try { is = connection . getErrorStream ( ) ; if ( is != null ) { if ( isZipped ) { is = new GZIPInputStream ( is ) ; } } return Util . readStringFromInputStream ( is , "UTF-8" ) ; } finally { Util . ensureClosed ( is ) ; } } return null ; }
Reads error response and returns it as a string . Handles gzipped streams .