|
@@ -2,12 +2,15 @@ import React, { useContext } from 'react';
|
|
import axiosInstance from '../../http/Axios';
|
|
import axiosInstance from '../../http/Axios';
|
|
import { rootContext } from '../../context/Root';
|
|
import { rootContext } from '../../context/Root';
|
|
import { CODE_STATUS } from '../../consts/Http';
|
|
import { CODE_STATUS } from '../../consts/Http';
|
|
|
|
+import { authContext } from '../../context/Auth';
|
|
|
|
+import { MILVUS_ADDRESS } from '../../consts/Localstorage';
|
|
|
|
|
|
let axiosResInterceptor: number | null = null;
|
|
let axiosResInterceptor: number | null = null;
|
|
// let timer: Record<string, ReturnType<typeof setTimeout> | number>[] = [];
|
|
// let timer: Record<string, ReturnType<typeof setTimeout> | number>[] = [];
|
|
// we only take side effect here, nothing else
|
|
// we only take side effect here, nothing else
|
|
const GlobalEffect = (props: { children: React.ReactNode }) => {
|
|
const GlobalEffect = (props: { children: React.ReactNode }) => {
|
|
const { openSnackBar } = useContext(rootContext);
|
|
const { openSnackBar } = useContext(rootContext);
|
|
|
|
+ const { setIsAuth, setAddress } = useContext(authContext);
|
|
|
|
|
|
// catch axios error here
|
|
// catch axios error here
|
|
if (axiosResInterceptor === null) {
|
|
if (axiosResInterceptor === null) {
|
|
@@ -25,6 +28,11 @@ const GlobalEffect = (props: { children: React.ReactNode }) => {
|
|
switch (response.status) {
|
|
switch (response.status) {
|
|
case CODE_STATUS.UNAUTHORIZED:
|
|
case CODE_STATUS.UNAUTHORIZED:
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
|
|
+ case CODE_STATUS.FORBIDDEN:
|
|
|
|
+ setIsAuth(false);
|
|
|
|
+ setAddress('');
|
|
|
|
+ window.localStorage.removeItem(MILVUS_ADDRESS);
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|