Skip to content

Commit f32b284

Browse files
authored
Merge pull request #165 from brendandburns/pff
When watch can't parse an object, try to parse it to a Status.
2 parents 0a7e112 + 782079d commit f32b284

File tree

1 file changed

+19
-1
lines changed
  • util/src/main/java/io/kubernetes/client/util

1 file changed

+19
-1
lines changed

util/src/main/java/io/kubernetes/client/util/Watch.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
*/
1313
package io.kubernetes.client.util;
1414

15+
import com.google.gson.JsonParseException;
1516
import com.google.gson.annotations.SerializedName;
17+
import com.google.gson.reflect.TypeToken;
1618
import com.squareup.okhttp.Call;
1719
import com.squareup.okhttp.ResponseBody;
1820
import io.kubernetes.client.ApiClient;
1921
import io.kubernetes.client.ApiException;
2022
import io.kubernetes.client.JSON;
2123

24+
import io.kubernetes.client.models.V1Status;
2225
import java.io.IOException;
2326
import java.lang.reflect.Type;
2427
import java.util.Iterator;
@@ -46,9 +49,18 @@ public static class Response<T> {
4649
@SerializedName("object")
4750
public T object;
4851

52+
public V1Status status;
53+
4954
Response(String type, T object) {
5055
this.type = type;
5156
this.object = object;
57+
this.status = null;
58+
}
59+
60+
Response(String type, V1Status status) {
61+
this.type = type;
62+
this.object = null;
63+
this.status = status;
5264
}
5365
}
5466

@@ -99,7 +111,13 @@ public Response<T> next() {
99111
if (line == null) {
100112
throw new RuntimeException("Null response from the server.");
101113
}
102-
return json.deserialize(line, watchType);
114+
try {
115+
return json.deserialize(line, watchType);
116+
} catch (JsonParseException ex) {
117+
Type statusType = new TypeToken<Response<V1Status>>(){}.getType();
118+
Response<V1Status> status = json.deserialize(line, statusType);
119+
return new Response<T>(status.type, status.object);
120+
}
103121
} catch (IOException e) {
104122
throw new RuntimeException("IO Exception during next method.", e);
105123
}

0 commit comments

Comments
 (0)