Skip to content

Commit

Permalink
fix: provide unauthorized error msg if ex is unauthorized (#771)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Jul 23, 2024
1 parent d56d8c5 commit c84158e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c84158e

Please sign in to comment.