{"record":{"id":"ab890490f0fe5a84","repo":"siyuan-note/siyuan","slug":"response-statustext","errorCode":null,"errorMessage":"response.statusText","messagePattern":"response\\.statusText","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/menus/util.ts","lineNumber":295,"sourceCode":"        if (blob.type === \"image/png\") {\n            copyBlob(blob);\n            return;\n        }\n        const objectURL = URL.createObjectURL(blob);\n        const tempElement = document.createElement(\"img\");\n        tempElement.onload = () => {\n            imageToPNGClipboard(tempElement, blob.type.split(\";\")[0].trim().toLowerCase() === \"image/svg+xml\");\n            URL.revokeObjectURL(objectURL);\n        };\n        tempElement.onerror = () => {\n            URL.revokeObjectURL(objectURL);\n            showCopyError();\n        };\n        tempElement.src = objectURL;\n    };\n    fetch(link).then(async (response) => {\n        if (!response.ok) {\n            throw new Error(response.statusText);\n        }\n        blobToPNGClipboard(await response.blob());\n    }).catch(() => {\n        // fetch 失败时回退：以 CORS 模式加载后再导出（需目标服务器返回 ACAO）\n        const tempElement = document.createElement(\"img\");\n        tempElement.crossOrigin = \"anonymous\";\n        tempElement.onload = () => imageToPNGClipboard(tempElement);\n        tempElement.onerror = showCopyError;\n        tempElement.src = link;\n    });\n};\n","sourceCodeStart":277,"sourceCodeEnd":307,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/menus/util.ts#L277-L307","documentation":"copyPNGByLink fetches a remote image URL and copies it as PNG. When the HTTP response is not ok, it throws Error(response.statusText), so the message is whatever the server returned (e.g. 'Not Found', 'Forbidden', or an empty string on HTTP/2), and the catch handler falls back to a CORS-mode image load.","triggerScenarios":"fetch(link) resolves with a 4xx/5xx status: dead image link, hotlink protection, missing/Expired signed URL, or server error while copying an image by network URL.","commonSituations":"Pasting/copying an image from a site with hotlink protection (403), deleted assets (404), private images requiring cookies/auth, rate limiting (429), or HTTP/2 responses where statusText is empty.","solutions":["Open the link in a browser to confirm it still serves the image","Copy the image to the clipboard manually instead of by link, or download it locally first","If you control the server, fix the 403/CORS/hotlink-protection configuration","Note the message can be empty on HTTP/2 — check network status code in devtools for the real cause"],"exampleFix":"// before\nif (!response.ok) { throw new Error(response.statusText); }\n// after\nif (!response.ok) { throw new Error(`image fetch failed: HTTP ${response.status}`); }","handlingStrategy":"try-catch","validationCode":"const ok = await fetch(link, {method: \"HEAD\"}).then(r => r.ok).catch(() => false);","typeGuard":"const isImageResponse = (r: Response) => r.ok && (r.headers.get(\"content-type\") || \"\").startsWith(\"image/\");","tryCatchPattern":"try { const r = await fetch(link); if (!r.ok) throw new Error(`HTTP ${r.status}`); ... } catch { /* CORS-mode img fallback */ }","preventionTips":["Check response.status, not statusText (empty on HTTP/2)","Pre-validate image URLs with a HEAD request","Keep the CORS-mode img fallback for protected hosts"],"tags":["network","fetch","clipboard","image"],"backgroundTag":"http-error-response","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}