feat: 接口错误处理
This commit is contained in:
parent
0e58843896
commit
f6e393b3d2
|
@ -608,7 +608,8 @@ export function Home() {
|
|||
// setting
|
||||
const [openSettings, setOpenSettings] = useState(false);
|
||||
const config = useChatStore((state) => state.config);
|
||||
const [isAllow, setIsAllow] = useState(true);
|
||||
const [isAllow, setIsAllow] = useState(true); // 白名单状态
|
||||
const [isRequestErr, setIsRequestErr] = useState(false); // 接口报错状态
|
||||
|
||||
useEffect(() => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
|
@ -620,7 +621,12 @@ export function Home() {
|
|||
const { code, msg } = data;
|
||||
setIsAllow(code === 0);
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
// 接口错误处理
|
||||
.catch((error) => {
|
||||
setIsAllow(false);
|
||||
setIsRequestErr(true);
|
||||
console.error(error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
//const isWorkWechat = () => {
|
||||
|
@ -636,7 +642,7 @@ export function Home() {
|
|||
// return false;
|
||||
//}
|
||||
//};
|
||||
const isWorkWechat = () => {
|
||||
const isWorkWechat = () => {
|
||||
// 获取user-agent标识头
|
||||
const userAgent = window.navigator.userAgent;
|
||||
|
||||
|
@ -649,15 +655,12 @@ const isWorkWechat = () => {
|
|||
const ua = userAgent.toLowerCase();
|
||||
|
||||
// 判断ua和微信浏览器的标识头是否匹配
|
||||
if (
|
||||
/micromessenger/i.test(ua) &&
|
||||
/wxwork/i.test(ua)
|
||||
) {
|
||||
if (/micromessenger/i.test(ua) && /wxwork/i.test(ua)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
useSwitchTheme();
|
||||
|
||||
|
@ -677,9 +680,15 @@ const isWorkWechat = () => {
|
|||
: styles.container
|
||||
}`}
|
||||
>
|
||||
{!isWorkWechat() ? (
|
||||
{
|
||||
// 接口报错
|
||||
isRequestErr ? (
|
||||
<h2>服务出了点问题~</h2>
|
||||
) : // 不在企业微信
|
||||
!isWorkWechat() ? (
|
||||
<h2 className="not-wx-work">请在企业微信里使用ChatGPT</h2>
|
||||
) : typeof isAllow === "boolean" && !isAllow ? (
|
||||
) : // 不在白名单
|
||||
!isAllow ? (
|
||||
<h2 className="not-allow">
|
||||
<span className="text">您不在白名单内,请走工单审批使用Gpt~</span>
|
||||
<span onClick={goApply} className={styles["button"]}>
|
||||
|
@ -715,7 +724,9 @@ const isWorkWechat = () => {
|
|||
|
||||
<div className={styles["sidebar-tail"]}>
|
||||
<div className={styles["sidebar-actions"]}>
|
||||
<div className={styles["sidebar-action"] + " " + styles.mobile}>
|
||||
<div
|
||||
className={styles["sidebar-action"] + " " + styles.mobile}
|
||||
>
|
||||
<IconButton
|
||||
icon={<CloseIcon />}
|
||||
onClick={() => {
|
||||
|
@ -770,7 +781,8 @@ const isWorkWechat = () => {
|
|||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue