From 0ab0bfc375cc2b33b2a878b27ca5ee60f28f774a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 9 Nov 2026 05:59:03 +0000 Subject: [PATCH] fix: don't log network error in console when loading issue popup (#40288) * fix #40286 --------- Signed-off-by: wxiaoguang --- web_src/js/features/ref-issue.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/web_src/js/features/ref-issue.ts b/web_src/js/features/ref-issue.ts index 9143f990577..96588dc73ed 100644 --- a/web_src/js/features/ref-issue.ts +++ b/web_src/js/features/ref-issue.ts @@ -12,10 +12,11 @@ type IssueInfo = { const issueInfoCache = new Map(); -async function getIssueInfo(url: string): Promise { +async function getIssueInfo(url: string): Promise { if (issueInfoCache.has(url)) return issueInfoCache.get(url)!; const resp = await GET(url); - if (!resp.ok) throw new Error(resp.statusText || 'Unknown network error'); + // fetch already logs network errors in console, we can ignore network errors here + if (!resp.ok) return null; const data = await resp.json(); issueInfoCache.set(url, data); return data; @@ -26,6 +27,8 @@ async function showRefIssuePopup(link: HTMLAnchorElement, info: IssuePathInfo) { getIssueInfo(`${window.config.appSubUrl}/${info.ownerName}/${info.repoName}/${info.pathType}/${info.indexString}/info`), import('../components/ContextPopup.vue'), ]); + if (!data) return; + const el = document.createElement('div'); const app = createApp(ContextPopup, { issue: data.convertedIssue, @@ -56,21 +59,24 @@ export function initRefIssueContextPopup() { link.setAttribute('data-ref-issue-popup', ''); // delay so a mouse passing over the link doesn't fire a fetch - let timer: TimeoutId; - const cancel = () => { + let timer: TimeoutId | undefined; + const stopDelayedPopup = () => { + if (!timer) return; clearTimeout(timer); + timer = undefined; link.removeAttribute('data-ref-issue-popup'); - link.removeEventListener('mouseleave', cancel); + link.removeEventListener('mouseleave', stopDelayedPopup); }; timer = setTimeout(async () => { - link.removeEventListener('mouseleave', cancel); + link.removeEventListener('mouseleave', stopDelayedPopup); try { await showRefIssuePopup(link, issuePathInfo); } catch (err) { - console.error('Failed to load issue info:', err); - link.removeAttribute('data-ref-issue-popup'); + console.error('Failed to load issue popup info:', err); + } finally { + stopDelayedPopup(); } }, 300); - link.addEventListener('mouseleave', cancel); + link.addEventListener('mouseleave', stopDelayedPopup); }); }