ok2c closed pull request #126: replace empty HttpResponseException.message with 
statusCode
URL: https://github.com/apache/httpcomponents-client/pull/126
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/httpclient/src/main/java/org/apache/http/client/HttpResponseException.java 
b/httpclient/src/main/java/org/apache/http/client/HttpResponseException.java
index 38a8cb52d..a8235ff4c 100644
--- a/httpclient/src/main/java/org/apache/http/client/HttpResponseException.java
+++ b/httpclient/src/main/java/org/apache/http/client/HttpResponseException.java
@@ -26,6 +26,8 @@
  */
 package org.apache.http.client;
 
+import org.apache.http.util.TextUtils;
+
 /**
  * Signals a non 2xx HTTP response.
  *
@@ -38,7 +40,7 @@
     private final int statusCode;
 
     public HttpResponseException(final int statusCode, final String s) {
-        super(s);
+        super(TextUtils.isBlank(s) ? Integer.toString(statusCode) : s);
         this.statusCode = statusCode;
     }
 
diff --git 
a/httpclient/src/test/java/org/apache/http/impl/client/TestAbstractResponseHandler.java
 
b/httpclient/src/test/java/org/apache/http/impl/client/TestAbstractResponseHandler.java
index cfc2bd653..6ed72af58 100644
--- 
a/httpclient/src/test/java/org/apache/http/impl/client/TestAbstractResponseHandler.java
+++ 
b/httpclient/src/test/java/org/apache/http/impl/client/TestAbstractResponseHandler.java
@@ -90,4 +90,27 @@ public void testUnsuccessfulResponse() throws Exception {
         Mockito.verify(inStream).close();
     }
 
+    @SuppressWarnings("boxing")
+    @Test
+    public void testUnsuccessfulResponseEmptyReason() throws Exception {
+        final InputStream inStream = Mockito.mock(InputStream.class);
+        final HttpEntity entity = Mockito.mock(HttpEntity.class);
+        Mockito.when(entity.isStreaming()).thenReturn(true);
+        Mockito.when(entity.getContent()).thenReturn(inStream);
+        final StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 404, 
"");
+        final HttpResponse response = Mockito.mock(HttpResponse.class);
+        Mockito.when(response.getStatusLine()).thenReturn(sl);
+        Mockito.when(response.getEntity()).thenReturn(entity);
+
+        final BasicResponseHandler handler = new BasicResponseHandler();
+        try {
+            handler.handleResponse(response);
+            Assert.fail("HttpResponseException expected");
+        } catch (final HttpResponseException ex) {
+            Assert.assertEquals(404, ex.getStatusCode());
+            Assert.assertEquals("404", ex.getMessage());
+        }
+        Mockito.verify(entity).getContent();
+        Mockito.verify(inStream).close();
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to