Skip to content

Commit 9f9d13b

Browse files
committed
replaced InformationDialog by Messages.showMessageDialog
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 71811a6 commit 9f9d13b

File tree

4 files changed

+29
-94
lines changed

4 files changed

+29
-94
lines changed

src/main/kotlin/com/redhat/devtools/gateway/util/ExceptionUtils.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
package com.redhat.devtools.gateway.util
1313

14+
import com.google.gson.Gson
15+
import io.kubernetes.client.openapi.ApiException
16+
1417

1518
fun Throwable.rootMessage(): String {
1619
var cause: Throwable? = this
@@ -25,4 +28,23 @@ fun Throwable.rootMessage(): String {
2528
fun Throwable.messageWithoutPrefix(): String? {
2629
return message?.trim()
2730
?: message?.substringAfter(":")?.trim()
28-
}
31+
}
32+
33+
fun Throwable.message(): String {
34+
return if (this is ApiException) {
35+
message()
36+
} else {
37+
message.orEmpty()
38+
}
39+
}
40+
41+
fun ApiException.message(): String {
42+
val response = Gson().fromJson(responseBody, Map::class.java)
43+
val msg = try {
44+
response["message"]?.toString()
45+
} catch (e: Exception) {
46+
e.rootMessage()
47+
}
48+
return "Reason: $msg"
49+
}
50+

src/main/kotlin/com/redhat/devtools/gateway/view/InformationDialog.kt

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesServerStepView.kt

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
*/
1212
package com.redhat.devtools.gateway.view.steps
1313

14-
import com.google.gson.Gson
15-
import com.intellij.openapi.application.ApplicationManager
1614
import com.intellij.openapi.components.service
1715
import com.intellij.openapi.progress.ProgressManager
1816
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
@@ -27,11 +25,10 @@ import com.redhat.devtools.gateway.openshift.OpenShiftClientFactory
2725
import com.redhat.devtools.gateway.openshift.Projects
2826
import com.redhat.devtools.gateway.openshift.kube.KubeConfigBuilder
2927
import com.redhat.devtools.gateway.settings.DevSpacesSettings
30-
import com.redhat.devtools.gateway.util.rootMessage
31-
import com.redhat.devtools.gateway.view.InformationDialog
28+
import com.redhat.devtools.gateway.util.message
29+
import com.redhat.devtools.gateway.view.ui.Dialogs
3230
import com.redhat.devtools.gateway.view.ui.FilteringComboBox
3331
import com.redhat.devtools.gateway.view.ui.PasteClipboardMenu
34-
import io.kubernetes.client.openapi.ApiException
3532
import io.kubernetes.client.openapi.auth.ApiKeyAuth
3633
import io.kubernetes.client.util.Config
3734
import javax.swing.JComboBox
@@ -91,10 +88,7 @@ class DevSpacesServerStepView(private var devSpacesContext: DevSpacesContext) :
9188
Projects(client).list()
9289
success = true
9390
} catch (e: Exception) {
94-
val errorMsg = getMessage(e)
95-
ApplicationManager.getApplication().invokeLater {
96-
InformationDialog("Connection failed", errorMsg, component).show()
97-
}
91+
Dialogs.error(e.message(), "Connection failed")
9892
throw e
9993
}
10094
},
@@ -111,24 +105,6 @@ class DevSpacesServerStepView(private var devSpacesContext: DevSpacesContext) :
111105
return success
112106
}
113107

114-
private fun getMessage(e: Exception): String {
115-
return if (e is ApiException) {
116-
getMessage(e)
117-
} else {
118-
e.message.orEmpty()
119-
}
120-
}
121-
122-
private fun getMessage(e: ApiException): String {
123-
val response = Gson().fromJson(e.responseBody, Map::class.java)
124-
val msg = try {
125-
response["message"]?.toString()
126-
} catch (e: Exception) {
127-
e.rootMessage()
128-
}
129-
return String.format("Reason: %s", msg)
130-
}
131-
132108
private fun loadOpenShiftConnectionSettings() {
133109
tfServer.removeAllItems()
134110
allServers.forEach { tfServer.addItem(it) }

src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import com.redhat.devtools.gateway.openshift.DevWorkspaces
3030
import com.redhat.devtools.gateway.openshift.Projects
3131
import com.redhat.devtools.gateway.openshift.Utils
3232
import com.redhat.devtools.gateway.util.messageWithoutPrefix
33-
import com.redhat.devtools.gateway.view.InformationDialog
3433
import com.redhat.devtools.gateway.view.ui.Dialogs
3534
import java.awt.Component
3635
import javax.swing.DefaultListModel
@@ -179,14 +178,9 @@ class DevSpacesWorkspacesStepView(private var devSpacesContext: DevSpacesContext
179178

180179
private fun connect() {
181180
if (devSpacesContext.isConnected) {
182-
InformationDialog(
183-
"Connection failed",
184-
String.format(
185-
"Already connected to %s",
186-
devSpacesContext.devWorkspace.name
187-
),
188-
component
189-
).show()
181+
Dialogs.error("Connection failed",
182+
"Already connected to ${devSpacesContext.devWorkspace.name}",
183+
)
190184
return
191185
}
192186

0 commit comments

Comments
 (0)