Skip to content

Commit 001b99d

Browse files
committed
fix: 修复了copilot提出的一个报错处理不完善的问题
1 parent dafa97f commit 001b99d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/components/DocsDestinationForm.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ export function DocsDestinationForm({ onChange }: DocsDestinationFormProps) {
3434
setTree(data.tree || []);
3535
}
3636
} catch {
37-
const res = await fetch("/docs-tree.json").catch(() => null);
38-
const data = await res?.json();
39-
if (mounted && data?.ok) {
40-
setTree(data.tree || []);
37+
// API 失败是预期行为(开发环境常见),静默回退到静态文件
38+
try {
39+
const res = await fetch("/docs-tree.json");
40+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
41+
const data = await res.json();
42+
if (mounted && data?.ok) {
43+
setTree(data.tree || []);
44+
}
45+
} catch (fallbackError) {
46+
// 静态文件也失败才是真正的问题
47+
console.error("无法加载文档目录树:", fallbackError);
48+
// 用户仍可继续使用,但无法选择目录
4149
}
4250
} finally {
4351
if (mounted) setLoading(false);

0 commit comments

Comments
 (0)