Skip to content

Commit 6ad0476

Browse files
committed
error data
1 parent cd3c683 commit 6ad0476

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package org.digma.intellij.plugin.ui.jcef.pluginapi
2+
3+
data class ErrorData(val error: String)

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/pluginapi/RecentActivityBadgeCommand.kt

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.intellij.openapi.wm.ToolWindow
88
import com.intellij.openapi.wm.ToolWindowManager
99
import org.digma.intellij.plugin.PluginId
1010
import org.digma.intellij.plugin.common.EDT
11+
import org.digma.intellij.plugin.common.objectToJson
1112
import org.digma.intellij.plugin.icons.AppIcons
1213
import org.digma.intellij.plugin.ui.jcef.jsonToObject
1314
import java.beans.ConstructorProperties
@@ -23,13 +24,45 @@ class RecentActivityBadgeCommand : Command() {
2324
headers: Map<String, String>
2425
): PluginApiHttpResponse {
2526

26-
val badgeRequest = postData?.let { jsonToObject(it, BadgeRequest::class.java) }
27+
try {
28+
val badgeRequest = postData?.let { jsonToObject(it, BadgeRequest::class.java) }
29+
30+
if (badgeRequest == null) {
31+
// Return 400 Bad Request, with a small error body
32+
val error = ErrorData("Invalid or missing badge request")
33+
val errorJson = objectToJson(error).toByteArray()
34+
return PluginApiHttpResponse(
35+
status = 400,
36+
headers = mutableMapOf(
37+
"Content-Type" to "application/json",
38+
"Content-Length" to errorJson.size.toString()
39+
),
40+
contentLength = errorJson.size.toLong(),
41+
contentType = "application/json",
42+
contentStream = errorJson.inputStream()
43+
)
44+
}
45+
46+
val recentActivityToolWindowIconChanger = RecentActivityToolWindowIconChanger(project)
47+
if (badgeRequest.status) {
48+
recentActivityToolWindowIconChanger.showBadge()
49+
} else {
50+
recentActivityToolWindowIconChanger.hideBadge()
51+
}
2752

28-
if (badgeRequest == null) {
29-
// Return 400 Bad Request, with a small error body
30-
val errorJson = """{"error":"Invalid or missing badge request"}""".toByteArray()
3153
return PluginApiHttpResponse(
32-
status = 400,
54+
status = 200,
55+
headers = headers.toMutableMap(),
56+
contentLength = 0,
57+
contentType = null,
58+
contentStream = null
59+
)
60+
} catch (e: Throwable) {
61+
val errorMessage = e.message ?: e.toString()
62+
val error = ErrorData(errorMessage)
63+
val errorJson = objectToJson(error).toByteArray()
64+
return PluginApiHttpResponse(
65+
status = 500,
3366
headers = mutableMapOf(
3467
"Content-Type" to "application/json",
3568
"Content-Length" to errorJson.size.toString()
@@ -40,20 +73,6 @@ class RecentActivityBadgeCommand : Command() {
4073
)
4174
}
4275

43-
val recentActivityToolWindowIconChanger = RecentActivityToolWindowIconChanger(project)
44-
if (badgeRequest.status) {
45-
recentActivityToolWindowIconChanger.showBadge()
46-
} else {
47-
recentActivityToolWindowIconChanger.hideBadge()
48-
}
49-
50-
return PluginApiHttpResponse(
51-
status = 200,
52-
headers = headers.toMutableMap(),
53-
contentLength = 0,
54-
contentType = null,
55-
contentStream = null
56-
)
5776
}
5877
}
5978

0 commit comments

Comments
 (0)