Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 17 additions & 8 deletions redisinsight/ui/src/slices/panels/aiAssistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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?.()
}
Expand Down
1 change: 1 addition & 0 deletions redisinsight/ui/src/utils/oauth/parseCloudOAuthError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<>
Expand Down