fix(config-ui): remove redirect offline when api throw a error (#5547)
diff --git a/config-ui/src/layouts/base/base.tsx b/config-ui/src/layouts/base/base.tsx
index 5ee3cfa..9cfdc10 100644
--- a/config-ui/src/layouts/base/base.tsx
+++ b/config-ui/src/layouts/base/base.tsx
@@ -17,12 +17,11 @@
*/
import React from 'react';
-import { useLocation } from 'react-router-dom';
+import { useHistory, useLocation } from 'react-router-dom';
import { Menu, MenuItem, Tag, Navbar, Intent, Alignment, Button } from '@blueprintjs/core';
import { PageLoading, Logo, ExternalLink } from '@/components';
import { useRefreshData } from '@/hooks';
-import { history } from '@/utils/history';
import DashboardIcon from '@/images/icons/dashborad.svg';
import FileIcon from '@/images/icons/file.svg';
@@ -39,10 +38,11 @@
}
export const BaseLayout = ({ children }: Props) => {
- const menu = useMenu();
+ const history = useHistory();
const { pathname } = useLocation();
- const { ready, data } = useRefreshData<{ version: string }>(() => API.getVersion(), []);
+ const menu = useMenu();
+ const { ready, data, error } = useRefreshData<{ version: string }>(() => API.getVersion(), []);
const token = window.localStorage.getItem('accessToken');
@@ -66,6 +66,10 @@
return import.meta.env.DEV ? `${protocol}//${hostname}:3002${suffix}` : `/grafana${suffix}`;
};
+ if (error) {
+ history.push('/offline');
+ }
+
if (!ready || !data) {
return <PageLoading />;
}
diff --git a/config-ui/src/utils/request.ts b/config-ui/src/utils/request.ts
index 3882364..14afa85 100644
--- a/config-ui/src/utils/request.ts
+++ b/config-ui/src/utils/request.ts
@@ -43,10 +43,6 @@
history.push('/db-migrate');
}
- if (status === 500) {
- history.push('/offline');
- }
-
return Promise.reject(error);
},
);