siyuan-note/siyuan · error
response.statusText
Error message
response.statusText
What it means
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.
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
Example fix
// before
if (!response.ok) { throw new Error(response.statusText); }
// after
if (!response.ok) { throw new Error(`image fetch failed: HTTP ${response.status}`); } Defensive patterns
Strategy: try-catch
Validate before calling
const ok = await fetch(link, {method: "HEAD"}).then(r => r.ok).catch(() => false); Type guard
const isImageResponse = (r: Response) => r.ok && (r.headers.get("content-type") || "").startsWith("image/"); Try / catch
try { const r = await fetch(link); if (!r.ok) throw new Error(`HTTP ${r.status}`); ... } catch { /* CORS-mode img fallback */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- download generated image failed with status
- panic during siyuan.client.fetch
- access to private/internal IP is prohibited
- access to private/internal IP is prohibited
- AI editor request timeout
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/ab890490f0fe5a84.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/menus/util.ts:295
if (blob.type === "image/png") {
copyBlob(blob);
return;
}
const objectURL = URL.createObjectURL(blob);
const tempElement = document.createElement("img");
tempElement.onload = () => {
imageToPNGClipboard(tempElement, blob.type.split(";")[0].trim().toLowerCase() === "image/svg+xml");
URL.revokeObjectURL(objectURL);
};
tempElement.onerror = () => {
URL.revokeObjectURL(objectURL);
showCopyError();
};
tempElement.src = objectURL;
};
fetch(link).then(async (response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
blobToPNGClipboard(await response.blob());
}).catch(() => {
// fetch 失败时回退:以 CORS 模式加载后再导出(需目标服务器返回 ACAO)
const tempElement = document.createElement("img");
tempElement.crossOrigin = "anonymous";
tempElement.onload = () => imageToPNGClipboard(tempElement);
tempElement.onerror = showCopyError;
tempElement.src = link;
});
};
View on GitHub (pinned to 9f775e8a12)