Skip to content

Commit

Permalink
Merge pull request #165 from brendandburns/pff
Browse files Browse the repository at this point in the history
When watch can't parse an object, try to parse it to a Status.
  • Loading branch information
mbohlool authored Jan 12, 2018
2 parents 0a7e112 + 782079d commit f32b284
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion util/src/main/java/io/kubernetes/client/util/Watch.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
*/
package io.kubernetes.client.util;

import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.ResponseBody;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.JSON;

import io.kubernetes.client.models.V1Status;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Iterator;
Expand Down Expand Up @@ -46,9 +49,18 @@ public static class Response<T> {
@SerializedName("object")
public T object;

public V1Status status;

Response(String type, T object) {
this.type = type;
this.object = object;
this.status = null;
}

Response(String type, V1Status status) {
this.type = type;
this.object = null;
this.status = status;
}
}

Expand Down Expand Up @@ -99,7 +111,13 @@ public Response<T> next() {
if (line == null) {
throw new RuntimeException("Null response from the server.");
}
return json.deserialize(line, watchType);
try {
return json.deserialize(line, watchType);
} catch (JsonParseException ex) {
Type statusType = new TypeToken<Response<V1Status>>(){}.getType();
Response<V1Status> status = json.deserialize(line, statusType);
return new Response<T>(status.type, status.object);
}
} catch (IOException e) {
throw new RuntimeException("IO Exception during next method.", e);
}
Expand Down

0 comments on commit f32b284

Please sign in to comment.