Skip to content

Commit e2a369e

Browse files
committed
#RI-5724 - handle 401 error on my data chat
1 parent 0a86eda commit e2a369e

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/shared/error-message/ErrorMessage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const ErrorMessage = (props: Props) => {
2121
const getErrorMessage = (error?: { statusCode: number, errorCode?: number }): string => {
2222
if (error?.statusCode === ApiStatusCode.Timeout) return AiChatErrors.Timeout
2323
if (error?.errorCode === CustomErrorCodes.GeneralAiUnexpectedError) return AiChatErrors.DefaultUnexpected
24-
if (error?.errorCode === CustomErrorCodes.CloudApiUnauthorized) return AiChatErrors.CloudAuthorization
2524

2625
return AiChatErrors.Default
2726
}

redisinsight/ui/src/slices/panels/aiAssistant.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { AxiosError } from 'axios'
55
import { apiService, localStorageService, sessionStorageService } from 'uiSrc/services'
66
import { ApiEndpoints, BrowserStorageItem } from 'uiSrc/constants'
77
import { AiChatMessage, AiChatType, StateAiAssistant } from 'uiSrc/slices/interfaces/aiAssistant'
8-
import { isStatusSuccessful, Maybe } from 'uiSrc/utils'
8+
import { isStatusSuccessful, Maybe, parseCloudOAuthError } from 'uiSrc/utils'
99
import { getBaseUrl } from 'uiSrc/services/apiService'
1010
import { getStreamedAnswer } from 'uiSrc/utils/api'
1111
import ApiStatusCode from 'uiSrc/constants/apiStatusCode'
1212
import { generateAiMessage, generateHumanMessage } from 'uiSrc/utils/transformers/chatbot'
13+
import { logoutUserAction } from 'uiSrc/slices/oauth/cloud'
14+
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
1315
import { AppDispatch, RootState } from '../store'
1416

1517
const getTabSelected = (tab?: string): AiChatType => {
@@ -340,13 +342,20 @@ export function askExpertChatbotAction(
340342
onFinish?.()
341343
},
342344
onError: (error: any) => {
343-
dispatch(setExpertQuestionError({
344-
id: humanMessage.id,
345-
error: {
346-
statusCode: error?.status ?? 500,
347-
errorCode: error?.errorCode
348-
}
349-
}))
345+
if (error?.status === ApiStatusCode.Unauthorized) {
346+
const err = parseCloudOAuthError(error)
347+
dispatch(addErrorNotification(err))
348+
dispatch(logoutUserAction())
349+
} else {
350+
dispatch(setExpertQuestionError({
351+
id: humanMessage.id,
352+
error: {
353+
statusCode: error?.status ?? 500,
354+
errorCode: error?.errorCode
355+
}
356+
}))
357+
}
358+
350359
onError?.(error?.status ?? 500)
351360
onFinish?.()
352361
}

redisinsight/ui/src/utils/oauth/parseCloudOAuthError.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export const parseCloudOAuthError = (err: CustomError | string = DEFAULT_ERROR_M
113113

114114
case CustomErrorCodes.CloudCapiUnauthorized:
115115
case CustomErrorCodes.CloudApiUnauthorized:
116+
case CustomErrorCodes.QueryAiUnauthorized:
116117
title = 'Session expired'
117118
message = (
118119
<>

0 commit comments

Comments
 (0)