Skip to content

Commit 1727dec

Browse files
committed
show error details when fetching children fails (#28)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 8354bc8 commit 1727dec

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/TreeStructure.kt

+28-1
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,36 @@ open class TreeStructure(
248248
project
249249
) {
250250
override fun getLabel(element: java.lang.Exception): String {
251-
return "Error: ${element.message ?: "unspecified"}"
251+
return "Error: ${getMessage(element)}"
252252
}
253253

254+
private fun getMessage(e: Exception): String {
255+
val causeMessage = e.cause?.message
256+
return if (causeMessage == null) {
257+
getMessageOrDefault(e)
258+
} else if (causeMessage.contains("Operation: ")) {
259+
/**
260+
* ex. minikube: KubernetesClientException:
261+
* "Operation: [list] for kind: [Service] with name: [null] in namespace: [default] failed."
262+
*/
263+
return e.cause?.cause?.message
264+
?: getMessageOrDefault(e)
265+
} else {
266+
/**
267+
* ex. OpenShift: KubernetesClientException:
268+
* "Failure executing: GET at: https://api.sandbox-m3.1530.p1.openshiftapps.com:6443/apis/project.openshift.io/v1/projects.
269+
* Message: Unauthorized! Token may have expired! Please log-in again. Unauthorized."
270+
*/
271+
causeMessage.substringAfter("Message: ", causeMessage)
272+
}
273+
}
274+
275+
private fun getMessageOrDefault(e: Exception): String {
276+
return e.message
277+
?: "unspecified"
278+
}
279+
280+
254281
override fun getIcon(element: java.lang.Exception): Icon {
255282
return AllIcons.General.BalloonError
256283
}

0 commit comments

Comments
 (0)