Skip to content

Commit dbeec62

Browse files
authored
fix(amazonq): include failure context in chat failure message (#5752)
1 parent 1007aff commit dbeec62

File tree

2 files changed

+13
-2
lines changed
  • plugins/amazonq

2 files changed

+13
-2
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ class BrowserConnector(
479479
} catch (_: CancellationException) {
480480
LOG.warn { "Cancelled chat generation" }
481481
} catch (e: Exception) {
482-
LOG.error(e) { "Failed to send chat message" }
482+
LOG.warn(e) { "Failed to send chat message" }
483483
browser.postChat(chatCommunicationManager.getErrorUiMessage(tabId, e, partialResultToken))
484484
}
485485
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/flareChat/ChatCommunicationManager.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat
55

66
import com.google.gson.Gson
7+
import com.google.gson.JsonObject
78
import com.intellij.openapi.components.Service
89
import com.intellij.openapi.components.service
910
import com.intellij.openapi.project.Project
1011
import kotlinx.coroutines.CompletableDeferred
1112
import kotlinx.coroutines.CoroutineScope
1213
import kotlinx.coroutines.launch
1314
import org.eclipse.lsp4j.ProgressParams
15+
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
1416
import software.aws.toolkits.core.utils.getLogger
17+
import software.aws.toolkits.core.utils.tryOrNull
1518
import software.aws.toolkits.core.utils.warn
1619
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
1720
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
@@ -22,6 +25,7 @@ import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.LSPAny
2225
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.AuthFollowUpClickedParams
2326
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.AuthFollowupType
2427
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_ERROR_PARAMS
28+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ChatMessage
2529
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ErrorParams
2630
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GetSerializedChatResult
2731
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.SEND_CHAT_COMMAND_PROMPT
@@ -122,8 +126,15 @@ class ChatCommunicationManager(private val cs: CoroutineScope) {
122126
token?.let {
123127
removePartialChatMessage(it)
124128
}
129+
var errorMessage: String? = null
130+
if (exception is ResponseErrorException) {
131+
errorMessage = tryOrNull {
132+
Gson().fromJson(exception.responseError.data as JsonObject, ChatMessage::class.java).body
133+
} ?: exception.responseError.message
134+
}
135+
125136
val errorTitle = "An error occurred while processing your request."
126-
val errorMessage = "Details: ${exception.message}"
137+
errorMessage = errorMessage ?: "Details: ${exception.message}"
127138
val errorParams = Gson().toJson(ErrorParams(tabId, null, errorMessage, errorTitle)).toString()
128139
val isPartialResult = false
129140
val uiMessage = """

0 commit comments

Comments
 (0)