forked from redhat-developer/intellij-openshift-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dont 'fatal IDE error' when cluster is not reachable (redhat-dev…
…eloper#621) Signed-off-by: Andre Dietisheim <[email protected]>
- Loading branch information
Showing
3 changed files
with
126 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/jboss/tools/intellij/openshift/utils/ExceptionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
* 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 java.util.concurrent.CompletionException; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class ExceptionUtils { | ||
|
||
private static final Pattern PATTERN_COMPLETION_EXCEPTION_MESSAGE = Pattern.compile( | ||
"\"message\": \"([\\s\\S]+?)\"\\n", Pattern.MULTILINE); | ||
|
||
private ExceptionUtils() {} | ||
|
||
public static String getMessage(Exception e) { | ||
if (e instanceof CompletionException) { | ||
return getMessage((CompletionException) e); | ||
} else { | ||
return e.getMessage(); | ||
} | ||
} | ||
|
||
public static String getMessage(CompletionException e) { | ||
if (e.getMessage() == null) { | ||
return null; | ||
} | ||
Matcher matcher = PATTERN_COMPLETION_EXCEPTION_MESSAGE.matcher(e.getMessage()); | ||
if (!matcher.find()) { | ||
return e.getMessage(); | ||
} | ||
return matcher.group(1); | ||
} | ||
} | ||
|