Skip to content

Commit

Permalink
Merge pull request #2230 from digma-ai/add-error-to-ui-messages
Browse files Browse the repository at this point in the history
Add error to UI messages
  • Loading branch information
kshmidt-digma authored Jun 19, 2024
2 parents 395854a + 0cf3e4a commit c52117f
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.JsonNode
import com.intellij.openapi.project.Project
import org.cef.browser.CefBrowser
import org.digma.intellij.plugin.analytics.AnalyticsServiceException
import org.digma.intellij.plugin.log.Log
import org.digma.intellij.plugin.ui.assets.model.SetAssetsDataFiltersMessage
import org.digma.intellij.plugin.ui.assets.model.SetAssetsDataMessage
import org.digma.intellij.plugin.ui.assets.model.SetCategoriesDataMessage
import org.digma.intellij.plugin.ui.jcef.BaseCommonMessageRouterHandler
import org.digma.intellij.plugin.ui.jcef.getQueryMapFromPayload
import org.digma.intellij.plugin.ui.jcef.model.ErrorPayload
import org.digma.intellij.plugin.ui.jcef.serializeAndExecuteWindowPostMessageJavaScript

class AssetsMessageRouterHandler(project: Project) : BaseCommonMessageRouterHandler(project) {
Expand Down Expand Up @@ -39,9 +41,16 @@ class AssetsMessageRouterHandler(project: Project) : BaseCommonMessageRouterHand

Log.log(logger::trace, project, "pushCategories called")

val backendQueryParams = getQueryMapFromPayload(requestJsonNode, objectMapper)
val payload = objectMapper.readTree(AssetsService.getInstance(project).getAssetCategories(backendQueryParams))
val message = SetCategoriesDataMessage(payload)
val message = try {
val backendQueryParams = getQueryMapFromPayload(requestJsonNode, objectMapper)
val payload = objectMapper.readTree(AssetsService.getInstance(project).getAssetCategories(backendQueryParams))
SetCategoriesDataMessage(payload)
} catch (e: AnalyticsServiceException) {
Log.warnWithException(logger, project, e, "Error loading categories {}", e.message)
val error = ErrorPayload(e.meaningfulMessage)
val payload = objectMapper.readTree("{ \"assetCategories\": [] }")
SetCategoriesDataMessage(payload, error)
}
Log.log(logger::trace, project, "sending ASSETS/SET_CATEGORIES_DATA message")
serializeAndExecuteWindowPostMessageJavaScript(browser, message)
}
Expand All @@ -60,10 +69,18 @@ class AssetsMessageRouterHandler(project: Project) : BaseCommonMessageRouterHand
@Throws(JsonProcessingException::class)
private fun pushAssets(browser: CefBrowser, requestJsonNode: JsonNode) {

val backendQueryParams = getQueryMapFromPayload(requestJsonNode, objectMapper)
Log.log(logger::trace, project, "pushAssets called")
val payload = objectMapper.readTree(AssetsService.getInstance(project).getAssets(backendQueryParams))
val message = SetAssetsDataMessage(payload)
val message = try{
val backendQueryParams = getQueryMapFromPayload(requestJsonNode, objectMapper)
val assets = AssetsService.getInstance(project).getAssets(backendQueryParams)
val payload = objectMapper.readTree(assets)
SetAssetsDataMessage(payload)
}catch (e: AnalyticsServiceException){
Log.warnWithException(logger,project,e,"Error loading assets {}",e)
val error = ErrorPayload(e.meaningfulMessage)
val payload = objectMapper.readTree("")
SetAssetsDataMessage(payload,error)
}
Log.log(logger::trace, project, "sending ASSETS/SET_DATA message")
serializeAndExecuteWindowPostMessageJavaScript(browser, message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ class AssetsService(private val project: Project) : Disposable {

fun getAssetCategories(queryParams: Map<String, Any?>): String {
EDT.assertNonDispatchThread()

return try {
Log.log(logger::trace, project, "got get categories request")
val categories = AnalyticsService.getInstance(project).getAssetCategories(queryParams)
checkInsightExists()
Log.log(logger::trace, project, "got categories [{}]", categories)
categories
} catch (e: AnalyticsServiceException) {
Log.warnWithException(logger, project, e, "Error loading categories {}", e.message)
"{ \"assetCategories\": [] }"
}
Log.log(logger::trace, project, "got get categories request")
val categories = AnalyticsService.getInstance(project).getAssetCategories(queryParams)
checkInsightExists()
Log.log(logger::trace, project, "got categories [{}]", categories)
return categories
}


Expand All @@ -67,16 +61,10 @@ class AssetsService(private val project: Project) : Disposable {

fun getAssets(queryParams: MutableMap<String, Any>): String {
EDT.assertNonDispatchThread()

return try {
Log.log(logger::trace, project, "got get assets request")
val assets = AnalyticsService.getInstance(project).getAssets(queryParams)
Log.log(logger::trace, project, "got assets [{}]", assets)
assets
} catch (e: AnalyticsServiceException) {
Log.warnWithException(logger, project, e, "Error loading assets {}", e.message)
""
}
Log.log(logger::trace, project, "got get assets request")
val assets = AnalyticsService.getInstance(project).getAssets(queryParams)
Log.log(logger::trace, project, "got assets [{}]", assets)
return assets
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package org.digma.intellij.plugin.ui.assets.model

import com.fasterxml.jackson.databind.JsonNode
import org.digma.intellij.plugin.ui.jcef.JCEFGlobalConstants
import org.digma.intellij.plugin.ui.jcef.model.ErrorPayload

data class SetAssetsDataMessage(val payload: JsonNode) {
data class SetAssetsDataMessage(val payload: JsonNode,val error: ErrorPayload? = null) {
val type = JCEFGlobalConstants.REQUEST_MESSAGE_TYPE
val action = "ASSETS/SET_DATA"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package org.digma.intellij.plugin.ui.assets.model

import com.fasterxml.jackson.databind.JsonNode
import org.digma.intellij.plugin.ui.jcef.JCEFGlobalConstants
import org.digma.intellij.plugin.ui.jcef.model.ErrorPayload


data class SetCategoriesDataMessage(val payload: JsonNode) {
data class SetCategoriesDataMessage(val payload: JsonNode,val error: ErrorPayload? = null) {
val type = JCEFGlobalConstants.REQUEST_MESSAGE_TYPE
val action = "ASSETS/SET_CATEGORIES_DATA"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.digma.intellij.plugin.ui.insights.model.SetInsightsMarkAsReadMessage
import org.digma.intellij.plugin.ui.insights.model.SetUnDismissedData
import org.digma.intellij.plugin.ui.insights.model.SetUnDismissedMessage
import org.digma.intellij.plugin.ui.jcef.JCefComponent
import org.digma.intellij.plugin.ui.jcef.model.ErrorPayload
import org.digma.intellij.plugin.ui.jcef.serializeAndExecuteWindowPostMessageJavaScript


Expand All @@ -49,18 +50,18 @@ class InsightsService(val project: Project) : InsightsServiceImpl(project) {

fun refreshInsightsList(backendQueryParams: MutableMap<String, Any>) {

val insightsResponse = try {
val message = try {
val insights = AnalyticsService.getInstance(project).getInsights(backendQueryParams)
onInsightReceived(insights)
insights
SetInsightDataListMessage(insights)
} catch (e: AnalyticsServiceException) {
Log.debugWithException(logger, project, e, "Error loading insights {}", e.message)
"{\"totalCount\":0,\"insights\":[]}"
val error = ErrorPayload(e.meaningfulMessage)
SetInsightDataListMessage("{\"totalCount\":0,\"insights\":[]}",error)
}

val msg = SetInsightDataListMessage(insightsResponse)
jCefComponent?.let {
serializeAndExecuteWindowPostMessageJavaScript(it.jbCefBrowser.cefBrowser, msg)
serializeAndExecuteWindowPostMessageJavaScript(it.jbCefBrowser.cefBrowser, message)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package org.digma.intellij.plugin.ui.insights.model

import com.fasterxml.jackson.annotation.JsonRawValue
import org.digma.intellij.plugin.ui.jcef.JCEFGlobalConstants
import org.digma.intellij.plugin.ui.jcef.model.ErrorPayload

data class SetInsightDataListMessage( @JsonRawValue val payload: String) {
data class SetInsightDataListMessage( @JsonRawValue val payload: String,val error: ErrorPayload? = null) {
val type = JCEFGlobalConstants.REQUEST_MESSAGE_TYPE
val action = "INSIGHTS/SET_DATA_LIST"
}
174 changes: 87 additions & 87 deletions src/main/resources/webview/main/index.js

Large diffs are not rendered by default.

0 comments on commit c52117f

Please sign in to comment.