diff src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java @ 116:c92b50c9c99a

Slightly improved error handling if response entity could not be parsed.
author gernotbelger
date Wed, 13 Jun 2018 15:37:12 +0200
parents 4ffbc9f79905
children 5b184dc5b4a9
line wrap: on
line diff
--- a/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Mon Dec 28 17:54:40 2015 +0100
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Wed Jun 13 15:37:12 2018 +0200
@@ -146,15 +146,23 @@
 
         try {
             String   url    = serverUrl + "/create";
-            Document result = (Document) handler.handle(doPost(url, doc));
+            Response response = doPost(url, doc);
+            try {
+                Document result = (Document) handler.handle(response);
 
-            return creator == null
-                ? ArtifactProtocolUtils.extractArtifact(result)
-                : creator.create(result);
+                return creator == null
+                    ? ArtifactProtocolUtils.extractArtifact(result)
+                    : creator.create(result);
+            }
+            catch (IOException e) {
+                String entityAsText = response.getEntityAsText();
+                throw new ConnectionException(
+                        "Connection to server failed. No Artifact created. Response was: " + entityAsText, e);
+            }
         }
         catch (IOException ioe) {
             throw new ConnectionException(
-                "Connection to server failed. No Artifact created.");
+                "Connection to server failed. No Artifact created.", ioe);
         }
     }
 

http://dive4elements.wald.intevation.org