{"record":{"id":"db338345b07e8ee0","repo":"siyuan-note/siyuan","slug":"export-custom-font-failed-response-status","errorCode":null,"errorMessage":"export custom font failed: ${response.status}","messagePattern":"export custom font failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/src/util/customFont.ts","lineNumber":120,"sourceCode":"        console.warn(\"load custom font failed\", error);\n    }\n};\n\nexport const ensureSelectedCustomFonts = async (fonts: Array<{ family: string; weight: number }>) => {\n    await Promise.all(fonts.map((font) => ensureSelectedCustomFont(font.family, font.weight)));\n};\n\nexport const getExportCustomFontStyle = async (fonts: Array<{family: string}>) => {\n    const families = new Set(fonts.map((font) => font.family).filter((family) =>\n        family.startsWith(CUSTOM_FONT_FAMILY_PREFIX)));\n    if (window.siyuan.config.system.safeMode || families.size === 0) {\n        return \"\";\n    }\n    const customFonts = (await loadCustomFonts()).filter((font) => isValidCustomFont(font) && families.has(font.family));\n    const styles = await Promise.all(customFonts.map(async (font) => {\n        const response = await fetch(`/custom-fonts/${font.id}`);\n        if (!response.ok) {\n            throw new Error(`export custom font failed: ${response.status}`);\n        }\n        const blob = await response.blob();\n        const dataURL = await new Promise<string>((resolve, reject) => {\n            const reader = new FileReader();\n            reader.onload = () => resolve(reader.result as string);\n            reader.onerror = () => reject(reader.error);\n            reader.readAsDataURL(blob);\n        });\n        return `@font-face { font-family: \"${font.family}\"; src: url(\"${dataURL}\"); font-style: normal; font-weight: ${Math.max(1, Math.min(1000, font.weight || 400))}; }`;\n    }));\n    return styles.join(\"\\n\");\n};\n\nconst setCustomFontStyle = (font: ICustomFont) => {\n    let styleElement = document.getElementById(`customFontStyle-${font.id}`) as HTMLStyleElement;\n    if (!styleElement) {\n        styleElement = document.createElement(\"style\");\n        styleElement.id = `customFontStyle-${font.id}`;","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/util/customFont.ts#L102-L138","documentation":"getExportCustomFontStyle fetches each matching custom font binary from /custom-fonts/<id> and throws this Error when the HTTP response is not ok (fetch only rejects on network failure, not on HTTP error statuses). It reports the status code so the caller knows whether the font file was missing (404), forbidden (403), or the server errored (5xx).","triggerScenarios":"Calling getExportCustomFontStyle (app/src/util/customFont.ts:120) while a registered custom font's file cannot be served at /custom-fonts/<id>: font removed from disk after config still lists it, wrong font.id, or kernel serving errors during export/PDF preview.","commonSituations":"Exporting a document to PDF/HTML that references a custom font the kernel no longer has; fonts synced from another device without the font assets; typo'd or stale font.id in the custom-fonts config.","solutions":["Check that the font file exists under the workspace custom-fonts directory and re-upload it in settings - appearance","Verify the font.id in the custom fonts config matches a served asset (curl /custom-fonts/<id>)","Wrap the export call in try/catch and fall back to rendering without the custom font","Re-register the font (remove and re-add) to regenerate its ID mapping"],"exampleFix":"// before\nconst styles = await getExportCustomFontStyle(families);\n// after\nlet styles = \"\";\ntry {\n    styles = await getExportCustomFontStyle(families);\n} catch (e) {\n    console.warn(e.message);\n}","handlingStrategy":"fallback","validationCode":"const probe = await fetch(`/custom-fonts/${font.id}`, {method: \"HEAD\"});\nif (!probe.ok) return \"\"; // skip this font in export","typeGuard":null,"tryCatchPattern":"try { styles = await getExportCustomFontStyle(families); } catch (e) { styles = \"\"; console.warn(e.message); }","preventionTips":["Re-register custom fonts after moving workspaces between devices","Confirm font files exist under the workspace custom-fonts directory","Fall back to default fonts when a font asset is missing during export"],"tags":["http","font","export"],"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"}