From c84158ee607d91e45709cd908b79951418028165 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Tue, 16 Jul 2024 18:08:08 +0200 Subject: [PATCH] fix: provide unauthorized error msg if ex is unauthorized (#771) Signed-off-by: Andre Dietisheim --- .../intellij/kubernetes/editor/ClusterResource.kt | 12 +++++++----- .../kubernetes/editor/ClusterResourceTest.kt | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResource.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResource.kt index 87d4aa53c..fb49f93bd 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResource.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResource.kt @@ -112,11 +112,13 @@ open class ClusterResource protected constructor( context.get(initialResource) } catch (e: RuntimeException) { val message = - if (e is KubernetesClientException - && e.isUnsupported() - ) { - // api discovery error - e.status.message + if (e is KubernetesClientException) { + when { + // api discovery error + e.isUnsupported() -> e.status.message + e.isUnauthorized() -> "Unauthorized. Verify username and password, refresh token, etc." + else -> e.message + } } else { "Could not retrieve ${initialResource.kind} ${initialResource.metadata?.name ?: ""}" + " in version ${initialResource.apiVersion} from server" diff --git a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResourceTest.kt b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResourceTest.kt index 7a2f12c5d..96b8b43e2 100644 --- a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResourceTest.kt +++ b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ClusterResourceTest.kt @@ -98,7 +98,7 @@ class ClusterResourceTest { fun `#pull(true) should throw exception that happens when operator#get throws`() { // given whenever(context.get(any())) - .doThrow(KubernetesClientException("forbidden", 401, null)) + .doThrow(KubernetesClientException("forbidden", 401, StatusBuilder().withMessage("Unauthorized").build())) // when cluster.pull(true) }