fix(static): getNode仅401跳登录,其他异常提示原因并上抛

This commit is contained in:
qing committed 2026-08-02 12:19:02 +08:00
1 parent c3c07ab06d
commit c7364286b7
1 file changed
+9 -7
+9 -7
View File
@@ -6,8 +6,8 @@
*/ */
async function getNode(id) { async function getNode(id) {
try { try {
obj = { "pid": id } const obj = { "pid": id }
jsonBody = JSON.stringify(obj) const jsonBody = JSON.stringify(obj)
console.log(jsonBody) console.log(jsonBody)
const res = await fetch('/get_notes', { const res = await fetch('/get_notes', {
method: 'POST', method: 'POST',
@@ -19,7 +19,7 @@ async function getNode(id) {
}); });
const responseText = await res.text(); const responseText = await res.text();
// WAF 拦截:弹提示并中止,不能落入 catch(其会误跳登录页) // WAF 拦截:弹提示并中止,不能落入 catch(其会向上抛出)
if (window.WafTip && WafTip.isBlocked(res, responseText)) { if (window.WafTip && WafTip.isBlocked(res, responseText)) {
alert(WafTip.MESSAGE); alert(WafTip.MESSAGE);
return; return;
@@ -34,7 +34,7 @@ async function getNode(id) {
} }
if (res.status === 401) { if (res.status === 401) {
// 凭证失效(过期或网关重启),跳转重新登录 // 凭证失效(过期或网关重启),仅此一种情况跳转重新登录
location.href = '/login.html'; location.href = '/login.html';
return; return;
} }
@@ -53,10 +53,12 @@ async function getNode(id) {
//} //}
} catch (err) { } catch (err) {
// 获取节点失败(非 JSON 响应 / HTTP 错误 / 网络异常),统一跳转登录页 // 非 401 失败(网络异常 / 5xx / 非 JSON 响应):提示真实原因并向上抛出,
// 调用方 .then(load_notes/loadMap) 不再执行,当前页面内容保持不变;
// 不再把任意错误误判为凭证失效而跳登录页
console.error('获取节点请求异常:', err); console.error('获取节点请求异常:', err);
location.href = '/login.html'; alert(err.message || '获取节点失败,请检查网络后重试');
} finally { throw err;
} }
} }