Browse Source

Added errorStream null check in HttpClient (used for testing purpose)

Luca Cavanna 12 years ago
parent
commit
f9f664bc3b

+ 6 - 4
src/test/java/org/elasticsearch/test/integration/rest/helper/HttpClient.java

@@ -105,10 +105,12 @@ public class HttpClient {
         } catch (IOException e) {
             InputStream errStream = urlConnection.getErrorStream();
             String body = null;
-            try {
-                body = Streams.copyToString(new InputStreamReader(errStream, Charsets.UTF_8));
-            } catch (IOException e1) {
-                throw new ElasticSearchException("problem reading error stream", e1);
+            if (errStream != null) {
+                try {
+                    body = Streams.copyToString(new InputStreamReader(errStream, Charsets.UTF_8));
+                } catch (IOException e1) {
+                    throw new ElasticSearchException("problem reading error stream", e1);
+                }
             }
             return new HttpClientResponse(body, errorCode, respHeaders, e);
         } finally {