diff --git a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts index 3c2ffadce8..ffd19babd9 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts @@ -920,7 +920,7 @@ describe('AgenticChatController', () => { }) }) - it('propagates error message to final chat result', async () => { + it('propagates model error back to client', async () => { generateAssistantResponseStub.callsFake(() => { throw new Error('Error') }) @@ -931,9 +931,12 @@ describe('AgenticChatController', () => { ) // These checks will fail if a response error is returned. - const typedChatResult = chatResult as ChatResult - assert.strictEqual(typedChatResult.type, 'answer') - assert.strictEqual(typedChatResult.body, 'Error') + const typedChatResult = chatResult as ResponseError + assert.strictEqual(typedChatResult.message, 'Error') + assert.strictEqual( + typedChatResult.data?.body, + 'An error occurred when communicating with the model, check the logs for more information.' + ) }) it('returns an auth follow up action if model request returns an auth error', async () => { diff --git a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts index ca8cdc129e..6f6368d342 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts @@ -759,13 +759,13 @@ export class AgenticChatController implements ChatHandlers { requestInput: RequestType, makeRequest: (requestInput: RequestType) => Promise ): Promise { - this.#debug(`Q Backend Request: ${JSON.stringify(requestInput)}`) + this.#debug(`Q Model Request: ${JSON.stringify(requestInput)}`) try { const response = await makeRequest(requestInput) - this.#debug(`Q Backend Response: ${JSON.stringify(response)}`) + this.#debug(`Q Model Response: ${JSON.stringify(response)}`) return response } catch (e) { - this.#features.logging.error(`Error in call: ${JSON.stringify(e)}`) + this.#features.logging.error(`Q Model Error: ${JSON.stringify(e)}`) throw new ModelServiceException(e as Error) } } @@ -1130,14 +1130,12 @@ export class AgenticChatController implements ChatHandlers { return createAuthFollowUpResult(authFollowType) } - const backendError = err.cause - // Send the backend error message directly to the client to be displayed in chat. - return { + return new ResponseError(LSPErrorCodes.RequestFailed, err.cause.message, { type: 'answer', - body: backendError.message, + body: 'An error occurred when communicating with the model, check the logs for more information.', messageId: errorMessageId, buttons: [], - } + }) } async onInlineChatPrompt(