diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index da84162f2ec..2dc5c88ed6c 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -249,11 +249,16 @@ export function registerMessageListeners( } catch (e) { languageClient.info(`Error occurred during chat request: ${e}`) // Use the last partial result if available, append error message + let body = '' + if (!cancellationToken.token.isCancellationRequested) { + body = lastPartialResult?.body + ? `${lastPartialResult.body}\n\n ❌ Error: Request failed to complete` + : '❌ An error occurred while processing your request' + } + const errorResult: ChatResult = { ...lastPartialResult, - body: lastPartialResult?.body - ? `${lastPartialResult.body}\n\n ❌ Error: Request failed to complete` - : '❌ An error occurred while processing your request', + body, } await handleCompleteResult(