Skip to content

Commit

Permalink
feat(provider/kubernetes): Show more in the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Wander committed Oct 17, 2017
1 parent bb69674 commit e4c852b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@

package com.netflix.spinnaker.clouddriver.kubernetes.v2.security;

import io.kubernetes.client.ApiException;

public class KubernetesApiException extends RuntimeException {
public KubernetesApiException(String operation, Throwable e) {
super(operation + " failed: " + e.getMessage(), e);
super(String.format("%s failed: %s", operation, e.getMessage()), e);
}

public KubernetesApiException(String operation, ApiException e) {
super(String.format("%s failed (%d %s): %s", operation, e.getCode(), e.getMessage(), e.getResponseBody()), e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,12 @@ public V1Service readService(String namespace, String name) {
private <T> T runAndRecordMetrics(String methodName, String namespace, Supplier<T> op) {
T result = null;
Throwable failure = null;
KubernetesApiException apiException = null;
long startTime = clock.monotonicTime();
try {
result = op.get();
} catch (KubernetesApiException e) {
failure = e.getCause();
apiException = e;
} catch (Exception e) {
failure = e;
} finally {
Expand All @@ -608,6 +609,8 @@ private <T> T runAndRecordMetrics(String methodName, String namespace, Supplier<

if (failure != null) {
throw new KubernetesApiException(methodName, failure);
} else if (apiException != null) {
throw apiException;
} else {
return result;
}
Expand Down

0 comments on commit e4c852b

Please sign in to comment.