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) }