diff --git a/iOSClient/Assistant/Chat/NCAssistantChatModel.swift b/iOSClient/Assistant/Chat/NCAssistantChatModel.swift index 06bf1c6330..e29e34e8db 100644 --- a/iOSClient/Assistant/Chat/NCAssistantChatModel.swift +++ b/iOSClient/Assistant/Chat/NCAssistantChatModel.swift @@ -63,15 +63,15 @@ class NCAssistantChatModel { showRetryResponseGenerationButton = false currentSession = nil - await loadAllMessages() - currentSession = await checkChatSession(sessionId: selectedConversation.id) - chatMessageTaskId = currentSession?.messageTaskId + await loadAllMessages() + currentSession = await checkChatSession(sessionId: selectedConversation.id) + chatMessageTaskId = currentSession?.messageTaskId - if messages.last?.isFromHuman == true, chatMessageTaskId == nil, isSending == false { - showRetryResponseGenerationButton = true - } else if chatMessageTaskId != nil { - startPollingForResponse() - } + if messages.last?.isFromHuman == true, chatMessageTaskId == nil, isSending == false { + showRetryResponseGenerationButton = true + } else if chatMessageTaskId != nil { + startPollingForResponse() + } } func generateChatSession() async { @@ -110,7 +110,8 @@ class NCAssistantChatModel { let result = await NextcloudKit.shared.checkAssistantChatGeneration(taskId: chatMessageTaskId, sessionId: selectedConversation?.id ?? 0, account: ncSession.account) - if result.error != .success { + // API sends expectation failed error (417) when a message is not ready yet. We should continue polling. + if result.error != .success, result.error.errorCode != NCGlobal.shared.errorExpectationFailed { stopPolling() await showErrorBanner(windowScene: windowScene, title: "_error_", text: "_assistant_error_generate_response_", errorCode: result.error.errorCode) return diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 70364d60bd..35425dc0c8 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -164,6 +164,7 @@ final class NCGlobal: Sendable { let errorConflict: Int = 409 let errorPreconditionFailed: Int = 412 let errorUnsupportedMediaType: Int = 415 + let errorExpectationFailed: Int = 417 let errorInternalServerError: Int = 500 let errorMaintenance: Int = 503 let errorQuota: Int = 507