diff --git a/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/shared/error-message/ErrorMessage.tsx b/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/shared/error-message/ErrorMessage.tsx index 8a21258a3f..5e8a4b1605 100644 --- a/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/shared/error-message/ErrorMessage.tsx +++ b/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/shared/error-message/ErrorMessage.tsx @@ -21,7 +21,6 @@ const ErrorMessage = (props: Props) => { const getErrorMessage = (error?: { statusCode: number, errorCode?: number }): string => { if (error?.statusCode === ApiStatusCode.Timeout) return AiChatErrors.Timeout if (error?.errorCode === CustomErrorCodes.GeneralAiUnexpectedError) return AiChatErrors.DefaultUnexpected - if (error?.errorCode === CustomErrorCodes.CloudApiUnauthorized) return AiChatErrors.CloudAuthorization return AiChatErrors.Default } diff --git a/redisinsight/ui/src/slices/panels/aiAssistant.ts b/redisinsight/ui/src/slices/panels/aiAssistant.ts index 4911a81067..106b0f6310 100644 --- a/redisinsight/ui/src/slices/panels/aiAssistant.ts +++ b/redisinsight/ui/src/slices/panels/aiAssistant.ts @@ -5,11 +5,13 @@ import { AxiosError } from 'axios' import { apiService, localStorageService, sessionStorageService } from 'uiSrc/services' import { ApiEndpoints, BrowserStorageItem } from 'uiSrc/constants' import { AiChatMessage, AiChatType, StateAiAssistant } from 'uiSrc/slices/interfaces/aiAssistant' -import { isStatusSuccessful, Maybe } from 'uiSrc/utils' +import { isStatusSuccessful, Maybe, parseCloudOAuthError } from 'uiSrc/utils' import { getBaseUrl } from 'uiSrc/services/apiService' import { getStreamedAnswer } from 'uiSrc/utils/api' import ApiStatusCode from 'uiSrc/constants/apiStatusCode' import { generateAiMessage, generateHumanMessage } from 'uiSrc/utils/transformers/chatbot' +import { logoutUserAction } from 'uiSrc/slices/oauth/cloud' +import { addErrorNotification } from 'uiSrc/slices/app/notifications' import { AppDispatch, RootState } from '../store' const getTabSelected = (tab?: string): AiChatType => { @@ -340,13 +342,20 @@ export function askExpertChatbotAction( onFinish?.() }, onError: (error: any) => { - dispatch(setExpertQuestionError({ - id: humanMessage.id, - error: { - statusCode: error?.status ?? 500, - errorCode: error?.errorCode - } - })) + if (error?.status === ApiStatusCode.Unauthorized) { + const err = parseCloudOAuthError(error) + dispatch(addErrorNotification(err)) + dispatch(logoutUserAction()) + } else { + dispatch(setExpertQuestionError({ + id: humanMessage.id, + error: { + statusCode: error?.status ?? 500, + errorCode: error?.errorCode + } + })) + } + onError?.(error?.status ?? 500) onFinish?.() } diff --git a/redisinsight/ui/src/utils/oauth/parseCloudOAuthError.tsx b/redisinsight/ui/src/utils/oauth/parseCloudOAuthError.tsx index 1d270b6535..fe1f559e18 100644 --- a/redisinsight/ui/src/utils/oauth/parseCloudOAuthError.tsx +++ b/redisinsight/ui/src/utils/oauth/parseCloudOAuthError.tsx @@ -113,6 +113,7 @@ export const parseCloudOAuthError = (err: CustomError | string = DEFAULT_ERROR_M case CustomErrorCodes.CloudCapiUnauthorized: case CustomErrorCodes.CloudApiUnauthorized: + case CustomErrorCodes.QueryAiUnauthorized: title = 'Session expired' message = ( <>