You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by GitBox <gi...@apache.org> on 2018/12/19 15:47:18 UTC

[GitHub] ok2c closed pull request #127: replace empty HttpResponseException.message with statusCode

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

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/httpclient5/src/main/java/org/apache/hc/client5/http/HttpResponseException.java b/httpclient5/src/main/java/org/apache/hc/client5/http/HttpResponseException.java
index 4d9b8edac..fab64d797 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/HttpResponseException.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/HttpResponseException.java
@@ -26,6 +26,8 @@
  */
 package org.apache.hc.client5.http;
 
+import org.apache.hc.core5.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/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java
index 0f0b23df2..d3e9c53bb 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java
@@ -71,6 +71,7 @@ public void testUnsuccessfulResponse() throws Exception {
         Mockito.when(entity.getContent()).thenReturn(inStream);
         final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
         Mockito.when(response.getCode()).thenReturn(404);
+        Mockito.when(response.getReasonPhrase()).thenReturn("NOT FOUND");
         Mockito.when(response.getEntity()).thenReturn(entity);
 
         final BasicHttpClientResponseHandler handler = new BasicHttpClientResponseHandler();
@@ -79,9 +80,32 @@ public void testUnsuccessfulResponse() throws Exception {
             Assert.fail("HttpResponseException expected");
         } catch (final HttpResponseException ex) {
             Assert.assertEquals(404, ex.getStatusCode());
+            Assert.assertEquals("NOT FOUND", ex.getMessage());
         }
         Mockito.verify(entity).getContent();
         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 ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
+        Mockito.when(response.getCode()).thenReturn(404);
+        Mockito.when(response.getEntity()).thenReturn(entity);
+
+        final BasicHttpClientResponseHandler handler = new BasicHttpClientResponseHandler();
+        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:
users@infra.apache.org


With regards,
Apache Git Services

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