fix(HEL-191): 补回问天解势知识文件兜底并消除 Failed to fetch
宿主机 data 挂载会遮盖镜像内 heaven_knowledge.json;增加不受挂载影响的 seed, 并将缺文件/坏 JSON 转为结构化中文错误,前端展示可读提示而非 Failed to fetch。 Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Cursor
multica-agent
parent
8a5e78f022
commit
ef86b31f6b
+19
-2
@@ -46,12 +46,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
function readableRequestError(error) {
|
||||
const message = String(error?.message || "");
|
||||
if (
|
||||
error instanceof TypeError
|
||||
|| /failed to fetch|networkerror|load failed|network request failed/i.test(message)
|
||||
) {
|
||||
return "网络请求失败,服务暂时不可用,请稍后重试。";
|
||||
}
|
||||
return message || "请求失败";
|
||||
}
|
||||
|
||||
async function request(url, method = "GET", body = null, options = {}) {
|
||||
const response = await fetch(url, requestOptions(method, body, options.signal));
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(url, requestOptions(method, body, options.signal));
|
||||
} catch (error) {
|
||||
throw new ApiError(readableRequestError(error), 0, null);
|
||||
}
|
||||
const payload = await parseJson(response);
|
||||
handleUnauthorized(response, url);
|
||||
if (!response.ok || payload.error) {
|
||||
throw new ApiError(payload.error || "请求失败", response.status, payload);
|
||||
const message = payload.message || payload.error || "请求失败";
|
||||
throw new ApiError(message, response.status, payload);
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user