diff --git a/apps/vscode/CHANGELOG.md b/apps/vscode/CHANGELOG.md index 5364c2632..0ddacb569 100644 --- a/apps/vscode/CHANGELOG.md +++ b/apps/vscode/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.136.0 (Unreleased) - Reduce memory usage by only starting the language server (LSP) in projects containing Quarto documents (https://github.com/quarto-dev/quarto/pull/1059) +- Improved the error message shown when inserting a citation from a DOI whose registration agency does not provide citation metadata (). ## 1.135.0 (Release on 2026-07-08) diff --git a/packages/editor-server/src/server/doi.ts b/packages/editor-server/src/server/doi.ts index 4dd97d200..5fd0c5254 100644 --- a/packages/editor-server/src/server/doi.ts +++ b/packages/editor-server/src/server/doi.ts @@ -28,9 +28,23 @@ export function doiServer() : DOIServer { return { async fetchCSL(doi: string) : Promise { const url = `${kDOIHost}/${doi}`; - return handleResponseWithStatus( - () => fetch(url, { headers: { Accept: kCSLJsonFormat } }) - ); + return handleResponseWithStatus(async () => { + const response = await fetch(url, { headers: { Accept: kCSLJsonFormat } }); + + // some registration agencies don't support CSL content negotiation; + // for those DOIs the request just redirects to the (HTML) landing + // page, so report that rather than failing to parse the page as JSON + const contentType = response.headers.get("Content-Type") || ""; + if (response.ok && !contentType.includes("json")) { + throw new Error( + "This DOI was found, but no citation data is available for it. " + + "This usually means the organization that registered the DOI does not support automatic citation lookup. " + + "To cite this work, you can add an entry to your bibliography manually." + ); + } + + return response; + }); } } }