Skip to content

Commit

Permalink
fix: display 'plz login' also when forbidden (#631)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Dec 7, 2023
1 parent 3e0de83 commit aaa311a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.fabric8.kubernetes.client.KubernetesClientException;
import org.jboss.tools.intellij.openshift.Constants;
import org.jboss.tools.intellij.openshift.utils.ExceptionUtils;
import org.jboss.tools.intellij.openshift.utils.KubernetesClientExceptionUtils;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -154,7 +155,8 @@ private Object[] getCurrentNamespace(ApplicationsRootNode element) {
private MessageNode<?> createErrorNode(ParentableNode<?> parent, Exception e) {
if (e instanceof KubernetesClientException) {
KubernetesClientException kce = (KubernetesClientException) e;
if (kce.getCode() == 401) {
if (KubernetesClientExceptionUtils.isForbidden(kce)
|| KubernetesClientExceptionUtils.isUnauthorized(kce)) {
return new MessageNode<>(root, parent, LOGIN);
} else if (kce.getCause() instanceof NoRouteToHostException) {
return new MessageNode<>(root, parent, kce.getCause().getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.utils;

import io.fabric8.kubernetes.client.KubernetesClientException;

import java.net.HttpURLConnection;

public class KubernetesClientExceptionUtils {

private KubernetesClientExceptionUtils() {}

public static boolean isForbidden(KubernetesClientException e) {
return HttpURLConnection.HTTP_FORBIDDEN == e.getCode();
}

public static boolean isUnauthorized(KubernetesClientException e) {
return HttpURLConnection.HTTP_UNAUTHORIZED == e.getCode();
}
}

0 comments on commit aaa311a

Please sign in to comment.