@@ -5,13 +5,21 @@ 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 , parseCloudOAuthError } from 'uiSrc/utils'
8
+ import {
9
+ getApiErrorCode ,
10
+ getApiErrorMessage ,
11
+ getAxiosError ,
12
+ isStatusSuccessful ,
13
+ Maybe ,
14
+ parseCloudOAuthError
15
+ } from 'uiSrc/utils'
9
16
import { getBaseUrl } from 'uiSrc/services/apiService'
10
17
import { getStreamedAnswer } from 'uiSrc/utils/api'
11
18
import ApiStatusCode from 'uiSrc/constants/apiStatusCode'
12
19
import { generateAiMessage , generateHumanMessage } from 'uiSrc/utils/transformers/chatbot'
13
20
import { logoutUserAction } from 'uiSrc/slices/oauth/cloud'
14
21
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
22
+ import { EnhancedAxiosError } from 'uiSrc/slices/interfaces'
15
23
import { AppDispatch , RootState } from '../store'
16
24
17
25
const getTabSelected = ( tab ?: string ) : AiChatType => {
@@ -303,7 +311,15 @@ export function getExpertChatHistoryAction(
303
311
dispatch ( getExpertChatHistorySuccess ( data ) )
304
312
onSuccess ?.( )
305
313
}
306
- } catch ( e ) {
314
+ } catch ( error ) {
315
+ const err = getAxiosError ( error as EnhancedAxiosError )
316
+ const errorCode = getApiErrorCode ( error as AxiosError )
317
+
318
+ if ( errorCode === ApiStatusCode . Unauthorized ) {
319
+ dispatch < any > ( logoutUserAction ( ) )
320
+ }
321
+
322
+ dispatch ( addErrorNotification ( err ) )
307
323
dispatch ( getExpertChatHistoryFailed ( ) )
308
324
}
309
325
}
@@ -378,8 +394,15 @@ export function removeExpertChatHistoryAction(
378
394
dispatch ( clearExpertChatHistory ( ) )
379
395
onSuccess ?.( )
380
396
}
381
- } catch ( e ) {
382
- // dispatch(getExpertChatHistoryFailed())
397
+ } catch ( error ) {
398
+ const err = getAxiosError ( error as EnhancedAxiosError )
399
+ const errorCode = getApiErrorCode ( error as AxiosError )
400
+
401
+ if ( errorCode === ApiStatusCode . Unauthorized ) {
402
+ dispatch < any > ( logoutUserAction ( ) )
403
+ }
404
+
405
+ dispatch ( addErrorNotification ( err ) )
383
406
}
384
407
}
385
408
}
0 commit comments