Skip to content

Commit 7ff1670

Browse files
author
Richard Lee
committed
Minor refactoring of error method
1 parent 1d38e93 commit 7ff1670

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

src/main/java/com/github/dockerjava/api/model/BuildResponseItem.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ public class BuildResponseItem extends ResponseItem {
1919
*/
2020
@JsonIgnore
2121
public boolean isBuildSuccessIndicated() {
22-
if (getStream() == null)
22+
if (isErrorIndicated() || getStream() == null) {
2323
return false;
24+
}
2425

2526
return getStream().contains(BUILD_SUCCESS);
2627
}
2728

2829
@JsonIgnore
2930
public String getImageId() {
30-
if (!isBuildSuccessIndicated())
31+
if (!isBuildSuccessIndicated()) {
3132
return null;
33+
}
3234

3335
return getStream().replaceFirst(BUILD_SUCCESS, "").trim();
3436
}

src/main/java/com/github/dockerjava/api/model/PullResponseItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public class PullResponseItem extends ResponseItem {
1818
*/
1919
@JsonIgnore
2020
public boolean isPullSuccessIndicated() {
21-
if (getStatus() == null)
21+
if (isErrorIndicated() || getStatus() == null) {
2222
return false;
23+
}
2324

2425
return (getStatus().contains("Download complete") || getStatus().contains("Image is up to date") || getStatus()
2526
.contains("Downloaded newer image"));

src/main/java/com/github/dockerjava/api/model/PushResponseItem.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@ public class PushResponseItem extends ResponseItem {
1111

1212
private static final long serialVersionUID = 8256977108011295857L;
1313

14-
/**
15-
* Returns whether the error field indicates an error
16-
*
17-
* @returns true: the error field indicates an error, false: the error field doesn't indicate an error
18-
*/
19-
@JsonIgnore
20-
public boolean isErrorIndicated() {
21-
if (getError() == null && getErrorDetail() == null)
22-
return false;
23-
24-
return true;
25-
}
2614
}

src/main/java/com/github/dockerjava/api/model/ResponseItem.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.Serializable;
44

5+
import com.fasterxml.jackson.annotation.JsonIgnore;
56
import org.apache.commons.lang.builder.ToStringBuilder;
67
import org.apache.commons.lang.builder.ToStringStyle;
78

@@ -25,6 +26,7 @@ public class ResponseItem implements Serializable {
2526
@JsonProperty("progressDetail")
2627
private ProgressDetail progressDetail;
2728

29+
@Deprecated
2830
@JsonProperty("progress")
2931
private String progress;
3032

@@ -40,6 +42,7 @@ public class ResponseItem implements Serializable {
4042
@JsonProperty("errorDetail")
4143
private ErrorDetail errorDetail;
4244

45+
@Deprecated
4346
@JsonProperty("error")
4447
private String error;
4548

@@ -81,6 +84,17 @@ public String getError() {
8184
return error;
8285
}
8386

87+
/**
88+
* Returns whether the error field indicates an error
89+
*
90+
* @returns true: the error field indicates an error, false: the error field doesn't indicate an error
91+
*/
92+
@JsonIgnore
93+
public boolean isErrorIndicated() {
94+
// check both the deprecated and current error fields, just in case
95+
return getError() != null || getErrorDetail() != null;
96+
}
97+
8498
@JsonIgnoreProperties(ignoreUnknown = false)
8599
public static class ProgressDetail implements Serializable {
86100
private static final long serialVersionUID = -1954994695645715264L;

0 commit comments

Comments
 (0)