Skip to content

Commit 541424f

Browse files
committed
🐛 增加网络请求失败时的报错
1 parent acda485 commit 541424f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

docs/app/components/Download.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,36 @@ export default function Download() {
1313
nightly: {},
1414
});
1515
const [loading, setLoading] = useState(true);
16+
const [error, setError] = useState<string | null>(null);
1617

1718
useEffect(() => {
1819
fetch("https://release.project-graph.top")
19-
.then((res) => res.json())
20+
.then((res) => {
21+
if (!res.ok) {
22+
throw new Error(`网络请求失败: ${res.status}`);
23+
}
24+
return res.json();
25+
})
2026
.then(setData)
27+
.catch((err) => {
28+
setError(err.message);
29+
})
2130
.finally(() => setLoading(false));
2231
}, []);
2332

24-
return loading ? (
25-
<Loader2 className="animate-spin" />
26-
) : (
33+
if (loading) {
34+
return <Loader2 className="animate-spin" />;
35+
}
36+
37+
if (error) {
38+
return (
39+
<div className="flex items-center justify-center">
40+
<p>获取下载链接失败,请联系开发者,或从Github Release界面或网盘下载</p>
41+
</div>
42+
);
43+
}
44+
45+
return (
2746
<Tabs items={["正式版", "开发版"]}>
2847
<Tab>
2948
<Downloads data={data.latest} />

0 commit comments

Comments
 (0)