diff --git a/src/main/java/org/jolokia/docker/maven/access/chunked/BuildResponseHandler.java b/src/main/java/org/jolokia/docker/maven/access/chunked/BuildResponseHandler.java index 0c734d348..16024a661 100644 --- a/src/main/java/org/jolokia/docker/maven/access/chunked/BuildResponseHandler.java +++ b/src/main/java/org/jolokia/docker/maven/access/chunked/BuildResponseHandler.java @@ -1,5 +1,6 @@ package org.jolokia.docker.maven.access.chunked; +import org.jolokia.docker.maven.access.DockerAccessException; import org.jolokia.docker.maven.util.Logger; import org.json.JSONObject; @@ -12,13 +13,19 @@ public BuildResponseHandler(Logger log) { } @Override - public void process(JSONObject json) { + public void process(JSONObject json) throws DockerAccessException { if (json.has("error")) { - log.error("Error building image: " + json.get("error")); + String msg = json.getString("error"); + log.error("Error building image: " + msg); + + String detailMsg = ""; if (json.has("errorDetail")) { JSONObject details = json.getJSONObject("errorDetail"); - log.error(details.getString("message")); + detailMsg = details.getString("message"); + log.error(detailMsg); } + throw new DockerAccessException("%s %s", json.get("error"), + (msg.equals(detailMsg) || "".equals(detailMsg) ? "" : "(" + detailMsg + ")")); } else if (json.has("stream")) { String message = json.getString("stream"); log.verbose(message.trim()); diff --git a/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseHandler.java b/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseHandler.java index 67e13dc93..f2935381a 100644 --- a/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseHandler.java +++ b/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseHandler.java @@ -1,5 +1,7 @@ package org.jolokia.docker.maven.access.chunked; +import org.jolokia.docker.maven.access.DockerAccessException; + public interface ChunkedResponseHandler { - void process(T toProcess); + void process(T toProcess) throws DockerAccessException; } diff --git a/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseReader.java b/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseReader.java index db1b5c3be..5f8fd5b21 100644 --- a/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseReader.java +++ b/src/main/java/org/jolokia/docker/maven/access/chunked/ChunkedResponseReader.java @@ -1,5 +1,7 @@ package org.jolokia.docker.maven.access.chunked; +import org.jolokia.docker.maven.access.DockerAccessException; + import java.io.IOException; import java.io.InputStream; @@ -13,7 +15,7 @@ public ChunkedResponseReader(InputStream stream, ChunkedResponseHandler this.handler = handler; } - public void process() throws IOException { + public void process() throws IOException, DockerAccessException { int len; int size = 8129; byte[] buf = new byte[size]; diff --git a/src/main/java/org/jolokia/docker/maven/access/chunked/PullOrPushResponseHandler.java b/src/main/java/org/jolokia/docker/maven/access/chunked/PullOrPushResponseHandler.java index 4db9e442c..a2c777161 100644 --- a/src/main/java/org/jolokia/docker/maven/access/chunked/PullOrPushResponseHandler.java +++ b/src/main/java/org/jolokia/docker/maven/access/chunked/PullOrPushResponseHandler.java @@ -1,5 +1,6 @@ package org.jolokia.docker.maven.access.chunked; +import org.jolokia.docker.maven.access.DockerAccessException; import org.jolokia.docker.maven.util.Logger; import org.json.JSONObject; @@ -14,7 +15,7 @@ public PullOrPushResponseHandler(Logger log) { } @Override - public void process(JSONObject json) { + public void process(JSONObject json) throws DockerAccessException { if (json.has("progressDetail")) { JSONObject details = json.getJSONObject("progressDetail"); if (details.has("total")) { @@ -35,6 +36,7 @@ public void process(JSONObject json) { String msg = json.getString("error").trim(); String details = json.getJSONObject("errorDetail").getString("message").trim(); log.error(msg + (msg.equals(details) ? "" : "(" + details + ")")); + throw new DockerAccessException("%s %s", msg, (msg.equals(details) ? "" : "(" + details + ")")); } else { log.info("... " + (json.has("id") ? json.getString("id") + ": " : "") + json.getString("status")); } diff --git a/src/main/java/org/jolokia/docker/maven/access/chunked/TextToJsonBridgeCallback.java b/src/main/java/org/jolokia/docker/maven/access/chunked/TextToJsonBridgeCallback.java index 0dd70d9b0..30aad0ad3 100644 --- a/src/main/java/org/jolokia/docker/maven/access/chunked/TextToJsonBridgeCallback.java +++ b/src/main/java/org/jolokia/docker/maven/access/chunked/TextToJsonBridgeCallback.java @@ -1,5 +1,6 @@ package org.jolokia.docker.maven.access.chunked; +import org.jolokia.docker.maven.access.DockerAccessException; import org.jolokia.docker.maven.util.Logger; import org.json.JSONException; import org.json.JSONObject; @@ -16,7 +17,7 @@ public TextToJsonBridgeCallback(Logger log, ChunkedResponseHandler h } @Override - public void process(String text) { + public void process(String text) throws DockerAccessException { try { JSONObject json = new JSONObject(text); handler.process(json);