Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: handle https code 50X error content

shuaid182a1ff54ba
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index a2a54361..9b1530c7 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -297,6 +297,8 @@ ui:
upgrade: Answer Upgrade
maintenance: Website Maintenance
users: Users
+ 404: HTTP Error 404
+ 50X: HTTP Error 500
notifications:
title: Notifications
inbox: Inbox
diff --git a/ui/src/pages/404/index.jsx b/ui/src/pages/404/index.jsx
index 90722e77..c4adcbe7 100644
--- a/ui/src/pages/404/index.jsx
+++ b/ui/src/pages/404/index.jsx
@@ -3,6 +3,9 @@ import { Container, Button } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
+// eslint-disable-next-line import/no-unresolved
+import { usePageTags } from '@/hooks';
+
const Index = () => {
const { t } = useTranslation('translation', { keyPrefix: 'page_404' });
useEffect(() => {
@@ -14,6 +17,10 @@ const Index = () => {
pageWrap.style.display = 'block';
};
}, []);
+
+ usePageTags({
+ title: t('404', { keyPrefix: 'page_title' }),
+ });
return (
<Container
className="d-flex flex-column justify-content-center align-items-center"
diff --git a/ui/src/pages/50X/index.jsx b/ui/src/pages/50X/index.jsx
index fd824b10..9ca0285e 100644
--- a/ui/src/pages/50X/index.jsx
+++ b/ui/src/pages/50X/index.jsx
@@ -3,6 +3,9 @@ import { Container, Button } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
+// eslint-disable-next-line import/no-unresolved
+import { usePageTags } from '@/hooks';
+
const Index = () => {
const { t } = useTranslation('translation', { keyPrefix: 'page_50X' });
useEffect(() => {
@@ -14,8 +17,14 @@ const Index = () => {
pageWrap.style.display = 'block';
};
}, []);
+
+ usePageTags({
+ title: t('50X', { keyPrefix: 'page_title' }),
+ });
return (
- <Container className="d-flex flex-column justify-content-center align-items-center page-wrap">
+ <Container
+ className="d-flex flex-column justify-content-center align-items-center"
+ style={{ flex: 1 }}>
<div
className="mb-4 text-secondary"
style={{ fontSize: '120px', lineHeight: 1.2 }}>
diff --git a/ui/src/pages/Layout/index.tsx b/ui/src/pages/Layout/index.tsx
index 88e0120c..a09bf113 100644
--- a/ui/src/pages/Layout/index.tsx
+++ b/ui/src/pages/Layout/index.tsx
@@ -4,7 +4,7 @@ import { HelmetProvider } from 'react-helmet-async';
import { SWRConfig } from 'swr';
-import { toastStore, loginToContinueStore, notFoundStore } from '@/stores';
+import { toastStore, loginToContinueStore, errorCode } from '@/stores';
import {
Header,
Footer,
@@ -16,6 +16,7 @@ import {
import { LoginToContinueModal } from '@/components/Modal';
import { useImgViewer } from '@/hooks';
import Component404 from '@/pages/404';
+import Component50X from '@/pages/50X';
const Layout: FC = () => {
const location = useLocation();
@@ -23,13 +24,13 @@ const Layout: FC = () => {
const closeToast = () => {
toastClear();
};
- const { visible: show404, hide: notFoundHide } = notFoundStore();
+ const { code: httpStatusCode, reset: httpStatusReset } = errorCode();
const imgViewer = useImgViewer();
const { show: showLoginToContinueModal } = loginToContinueStore();
useEffect(() => {
- notFoundHide();
+ httpStatusReset();
}, [location]);
return (
<HelmetProvider>
@@ -44,7 +45,13 @@ const Layout: FC = () => {
<div
className="position-relative page-wrap"
onClick={imgViewer.checkClickForImgView}>
- {show404 ? <Component404 /> : <Outlet />}
+ {httpStatusCode === '404' ? (
+ <Component404 />
+ ) : httpStatusCode === '50X' ? (
+ <Component50X />
+ ) : (
+ <Outlet />
+ )}
</div>
<Toast msg={toastMsg} variant={variant} onClose={closeToast} />
<Footer />
diff --git a/ui/src/stores/errorCode.ts b/ui/src/stores/errorCode.ts
new file mode 100644
index 00000000..336a213b
--- /dev/null
+++ b/ui/src/stores/errorCode.ts
@@ -0,0 +1,25 @@
+import create from 'zustand';
+
+type codeType = '404' | '50X' | '';
+
+interface NotFoundType {
+ code: codeType;
+ update: (code: codeType) => void;
+ reset: () => void;
+}
+
+const notFound = create<NotFoundType>((set) => ({
+ code: '',
+ update: (code: codeType) => {
+ set(() => {
+ return { code };
+ });
+ },
+ reset: () => {
+ set(() => {
+ return { code: '' };
+ });
+ },
+}));
+
+export default notFound;
diff --git a/ui/src/stores/index.ts b/ui/src/stores/index.ts
index 47dc0712..a6c3b143 100644
--- a/ui/src/stores/index.ts
+++ b/ui/src/stores/index.ts
@@ -10,7 +10,7 @@ import pageTagStore from './pageTags';
import customizeStore from './customize';
import themeSettingStore from './themeSetting';
import loginToContinueStore from './loginToContinue';
-import notFoundStore from './notFound';
+import errorCode from './errorCode';
export {
toastStore,
@@ -24,5 +24,5 @@ export {
themeSettingStore,
seoSettingStore,
loginToContinueStore,
- notFoundStore,
+ errorCode,
};
diff --git a/ui/src/stores/notFound.ts b/ui/src/stores/notFound.ts
deleted file mode 100644
index 35c361af..00000000
--- a/ui/src/stores/notFound.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import create from 'zustand';
-
-interface NotFoundType {
- visible: boolean;
- show: () => void;
- hide: () => void;
-}
-
-const notFound = create<NotFoundType>((set) => ({
- visible: false,
- show: () => {
- set(() => {
- return { visible: true };
- });
- },
- hide: () => {
- set(() => {
- return { visible: false };
- });
- },
-}));
-
-export default notFound;
diff --git a/ui/src/utils/request.ts b/ui/src/utils/request.ts
index 1629175b..0e58da26 100644
--- a/ui/src/utils/request.ts
+++ b/ui/src/utils/request.ts
@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
import type { AxiosInstance, AxiosRequestConfig, AxiosError } from 'axios';
import { Modal } from '@/components';
-import { loggedUserInfoStore, toastStore, notFoundStore } from '@/stores';
+import { loggedUserInfoStore, toastStore, errorCode } from '@/stores';
import { LOGGED_TOKEN_STORAGE_KEY, IGNORE_PATH_LIST } from '@/common/constants';
import { RouteAlias } from '@/router/alias';
import { getCurrentLang } from '@/utils/localize';
@@ -107,14 +107,14 @@ class Request {
// 401: Re-login required
if (status === 401) {
// clear userinfo
- notFoundStore.getState().hide();
+ errorCode.getState().reset();
loggedUserInfoStore.getState().clear();
floppyNavigation.navigateToLogin();
return Promise.reject(false);
}
if (status === 403) {
// Permission interception
- notFoundStore.getState().hide();
+ errorCode.getState().reset();
if (data?.type === 'url_expired') {
// url expired
floppyNavigation.navigate(RouteAlias.activationFailed, () => {
@@ -150,10 +150,14 @@ class Request {
if (isIgnoredPath(IGNORE_PATH_LIST)) {
return Promise.reject(false);
}
- notFoundStore.getState().show();
+ errorCode.getState().update('404');
return Promise.reject(false);
}
if (status >= 500) {
+ if (isIgnoredPath(IGNORE_PATH_LIST)) {
+ return Promise.reject(false);
+ }
+ errorCode.getState().update('50X');
console.error(
`Request failed with status code ${status}, ${msg || ''}`,
);