From 3f8173989c405b826e052a6bf55b122a1b1c1719 Mon Sep 17 00:00:00 2001 From: xuans Date: Sun, 30 Aug 2026 20:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AE=A1=E7=90=86=E6=80=BB?= =?UTF-8?q?=E8=A7=88=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/Dashboard/Dashboard.js | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/Dashboard/Dashboard.js b/frontend/src/views/Dashboard/Dashboard.js index ce95654..c6283d8 100644 --- a/frontend/src/views/Dashboard/Dashboard.js +++ b/frontend/src/views/Dashboard/Dashboard.js @@ -142,6 +142,15 @@ export function useDashboard() { return response; } + async function responseError(response, fallback) { + const result = await response.json().catch(() => ({})); + if (result.error) return result.error; + if (response.status === 403) return "当前账号没有管理权限"; + if (response.status === 409) return "当前服务状态不允许执行此操作"; + if (response.status >= 500) return "核心服务暂时不可用,请稍后重试"; + return fallback; + } + function createEmptyForm() { return { name: "", @@ -738,8 +747,18 @@ export function useDashboard() { fetchAdmin("/api/v1/audit-logs?limit=20"), fetchAdmin("/api/v1/settings"), ]); - if ([statusResponse, domainResponse, serverResponse, sshKeyResponse, certificateResponse, taskResponse, auditResponse, settingsResponse].some((response) => !response.ok)) { - throw new Error("读取管理数据失败"); + const failedResponse = [ + statusResponse, + domainResponse, + serverResponse, + sshKeyResponse, + certificateResponse, + taskResponse, + auditResponse, + settingsResponse, + ].find((response) => !response.ok); + if (failedResponse) { + throw new Error(await responseError(failedResponse, "读取管理数据失败")); } status.value = await statusResponse.json(); domains.value = (await domainResponse.json()).items || []; @@ -762,8 +781,8 @@ export function useDashboard() { }), ); domainServers.value = Object.fromEntries(associations); - } catch { - error.value = "无法连接核心服务,请先启动 scert serve"; + } catch (err) { + error.value = err.message || "无法连接核心服务,请先启动 scert serve"; } finally { loading.value = false; }