@@ -5,11 +5,13 @@ import { AxiosError } from 'axios'
5
5
import { apiService , localStorageService , sessionStorageService } from 'uiSrc/services'
6
6
import { ApiEndpoints , BrowserStorageItem } from 'uiSrc/constants'
7
7
import { AiChatMessage , AiChatType , StateAiAssistant } from 'uiSrc/slices/interfaces/aiAssistant'
8
- import { isStatusSuccessful , Maybe } from 'uiSrc/utils'
8
+ import { isStatusSuccessful , Maybe , parseCloudOAuthError } from 'uiSrc/utils'
9
9
import { getBaseUrl } from 'uiSrc/services/apiService'
10
10
import { getStreamedAnswer } from 'uiSrc/utils/api'
11
11
import ApiStatusCode from 'uiSrc/constants/apiStatusCode'
12
12
import { generateAiMessage , generateHumanMessage } from 'uiSrc/utils/transformers/chatbot'
13
+ import { logoutUserAction } from 'uiSrc/slices/oauth/cloud'
14
+ import { addErrorNotification } from 'uiSrc/slices/app/notifications'
13
15
import { AppDispatch , RootState } from '../store'
14
16
15
17
const getTabSelected = ( tab ?: string ) : AiChatType => {
@@ -340,13 +342,20 @@ export function askExpertChatbotAction(
340
342
onFinish ?.( )
341
343
} ,
342
344
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
+
350
359
onError ?.( error ?. status ?? 500 )
351
360
onFinish ?.( )
352
361
}
0 commit comments