Index: /trunk/src/org/openstreetmap/josm/tools/HttpClient.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/HttpClient.java	(revision 11249)
+++ /trunk/src/org/openstreetmap/josm/tools/HttpClient.java	(revision 11250)
@@ -6,4 +6,5 @@
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -190,4 +191,5 @@
         private boolean uncompress;
         private boolean uncompressAccordingToContentDisposition;
+        private String responseData = null;
 
         private Response(HttpURLConnection connection, ProgressMonitor monitor) throws IOException {
@@ -198,4 +200,22 @@
             this.responseCode = connection.getResponseCode();
             this.responseMessage = connection.getResponseMessage();
+            if (this.responseCode >= 300) {
+                String contentType = getContentType();
+                if (contentType == null || (
+                        contentType.contains("text") ||
+                        contentType.contains("html") ||
+                        contentType.contains("xml"))
+                        ) {
+                    String content = this.fetchContent();
+                    if (content == null || content.isEmpty()) {
+                        Main.debug("Server did not return any body");
+                    } else {
+                        Main.debug("Response body: ");
+                        Main.debug(this.fetchContent());
+                    }
+                } else {
+                    Main.debug("Server returned content: {0} of length: {1}. Not printing.", contentType, this.getContentLength());
+                }
+            }
         }
 
@@ -264,4 +284,7 @@
                 Main.debug(ioe);
                 in = connection.getErrorStream();
+                if (in == null) {
+                    in = new ByteArrayInputStream(new byte[]{});
+                }
             }
             if (in != null) {
@@ -306,9 +329,11 @@
          * @throws IOException if any I/O error occurs
          */
-        @SuppressWarnings("resource")
-        public String fetchContent() throws IOException {
-            try (Scanner scanner = new Scanner(getContentReader()).useDelimiter("\\A")) {
-                return scanner.hasNext() ? scanner.next() : "";
-            }
+        public synchronized String fetchContent() throws IOException {
+            if (responseData == null) {
+                try (Scanner scanner = new Scanner(getContentReader()).useDelimiter("\\A")) { // \A - beginning of input
+                    responseData = scanner.hasNext() ? scanner.next() : "";
+                }
+            }
+            return responseData;
         }
 
Index: /trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
===================================================================
--- /trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java	(revision 11249)
+++ /trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java	(revision 11250)
@@ -13,4 +13,6 @@
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
 
 import javax.json.JsonObject;
@@ -40,7 +42,27 @@
     private ProgressMonitor progress;
 
+    private LogRecord captured;
+    private final Handler handler = new Handler() {
+
+        @Override
+        public void publish(LogRecord record) {
+            captured = record;
+        }
+
+        @Override
+        public void flush() {
+        }
+
+        @Override
+        public void close() throws SecurityException {
+        }
+    };
+
     @Before
     public void setUp() {
         progress = TestUtils.newTestProgressMonitor();
+        captured = null;
+        Logging.getLogger().addHandler(handler);
+        Logging.getLogger().setLevel(Logging.LEVEL_DEBUG);
     }
 
@@ -154,5 +176,68 @@
         final String content = response.fetchContent();
         assertThat(content, containsString("-=[ teapot ]=-"));
-    }
+        assertThat(captured.getMessage(), containsString("-=[ teapot ]=-"));
+        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
+    }
+
+    @Test()
+    public void testHttp401() throws IOException {
+        // https://tools.ietf.org/html/rfc2324
+        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/401")).connect(progress);
+        assertThat(response.getResponseCode(), is(401));
+        assertThat(response.getResponseMessage(), is("UNAUTHORIZED"));
+        final String content = response.fetchContent();
+        assertThat(content, is(""));
+        assertThat(captured.getMessage(), containsString("Server did not return any body"));
+        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
+    }
+
+    @Test
+    public void testHttp402() throws IOException {
+        // https://tools.ietf.org/html/rfc2324
+        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/402")).connect(progress);
+        assertThat(response.getResponseCode(), is(402));
+        assertThat(response.getResponseMessage(), is("PAYMENT REQUIRED"));
+        final String content = response.fetchContent();
+        assertThat(content, containsString("Fuck you, pay me!"));
+        assertThat(captured.getMessage(), containsString("Fuck you, pay me!"));
+        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
+    }
+
+    @Test
+    public void testHttp403() throws IOException {
+        // https://tools.ietf.org/html/rfc2324
+        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/403")).connect(progress);
+        assertThat(response.getResponseCode(), is(403));
+        assertThat(response.getResponseMessage(), is("FORBIDDEN"));
+        final String content = response.fetchContent();
+        assertThat(content, is(""));
+        assertThat(captured.getMessage(), containsString("Server did not return any body"));
+        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
+    }
+
+    @Test
+    public void testHttp404() throws IOException {
+        // https://tools.ietf.org/html/rfc2324
+        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/404")).connect(progress);
+        assertThat(response.getResponseCode(), is(404));
+        assertThat(response.getResponseMessage(), is("NOT FOUND"));
+        final String content = response.fetchContent();
+        assertThat(content, is(""));
+        assertThat(captured.getMessage(), containsString("Server did not return any body"));
+        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
+    }
+
+    @Test
+    public void testHttp500() throws IOException {
+        // https://tools.ietf.org/html/rfc2324
+        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/500")).connect(progress);
+        assertThat(response.getResponseCode(), is(500));
+        assertThat(response.getResponseMessage(), is("INTERNAL SERVER ERROR"));
+        final String content = response.fetchContent();
+        assertThat(content, containsString(""));
+        assertThat(captured.getMessage(), containsString("Server did not return any body"));
+        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
+    }
+
 
     @Test
