You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/10/28 15:32:10 UTC
jclouds-labs git commit: Always throw an Exception if the response is
failed
Repository: jclouds-labs
Updated Branches:
refs/heads/master b09b1d9a2 -> bf9ed5b8d
Always throw an Exception if the response is failed
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/bf9ed5b8
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/bf9ed5b8
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/bf9ed5b8
Branch: refs/heads/master
Commit: bf9ed5b8db0eb71d7fd69c419a6f081677e9d097
Parents: b09b1d9
Author: Ignasi Barrera <na...@apache.org>
Authored: Fri Oct 28 17:32:00 2016 +0200
Committer: Ignasi Barrera <na...@apache.org>
Committed: Fri Oct 28 17:32:00 2016 +0200
----------------------------------------------------------------------
.../handlers/ProfitBricksHttpErrorHandler.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf9ed5b8/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/handlers/ProfitBricksHttpErrorHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/handlers/ProfitBricksHttpErrorHandler.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/handlers/ProfitBricksHttpErrorHandler.java
index 74d600f..2fb95f8 100644
--- a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/handlers/ProfitBricksHttpErrorHandler.java
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/handlers/ProfitBricksHttpErrorHandler.java
@@ -16,6 +16,8 @@
*/
package org.apache.jclouds.profitbricks.rest.handlers;
+import java.io.IOException;
+
import javax.inject.Singleton;
import org.apache.jclouds.profitbricks.rest.exceptions.ProfitBricksRateLimitExceededException;
@@ -26,6 +28,7 @@ import org.jclouds.http.HttpResponseException;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.InsufficientResourcesException;
import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.util.Strings2;
/**
* Parse ProfitBricks API errors and set the appropriate exception.
@@ -69,9 +72,26 @@ public class ProfitBricksHttpErrorHandler implements HttpErrorHandler {
else
exception = new InsufficientResourcesException(response.getMessage(), exception);
break;
+ default:
+ String message = parseMessage(response);
+ exception = message == null ? new HttpResponseException(command, response) : new HttpResponseException(
+ command, response, message);
+ break;
+
}
} finally {
command.setException(exception);
}
}
+
+ public String parseMessage(final HttpResponse response) {
+ if (response.getPayload() == null) {
+ return null;
+ }
+ try {
+ return Strings2.toStringAndClose(response.getPayload().openStream());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}