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