From 37e3c0975f0f79c7475e189e265ee8e1fb89764d Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:18:54 +0100 Subject: [PATCH 1/2] [Snippets] Add error handling to rewrite-site-links.mdx --- .../docs/rules/snippets/examples/rewrite-site-links.mdx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx b/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx index 78a7063352ccc0..92a9653c1e6e00 100644 --- a/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx +++ b/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx @@ -40,7 +40,14 @@ export default { .on("img", new AttributeRewriter("src")); const res = await fetch(request); + if (!res.headers.has("Content-Type")) { + return res; + } + const contentType = res.headers.get("Content-Type"); + if (typeof contentType !== "string") { + return res; + } // If the response is HTML, it can be transformed with // HTMLRewriter -- otherwise, it should pass through @@ -51,4 +58,4 @@ export default { } }, }; -``` \ No newline at end of file +``` From c9ae0b6c34d9369a6191d791517c8f4cc171f4c1 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:23:30 +0100 Subject: [PATCH 2/2] Remove empty line --- src/content/docs/rules/snippets/examples/rewrite-site-links.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx b/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx index 92a9653c1e6e00..e5ea0222bea4d9 100644 --- a/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx +++ b/src/content/docs/rules/snippets/examples/rewrite-site-links.mdx @@ -43,7 +43,6 @@ export default { if (!res.headers.has("Content-Type")) { return res; } - const contentType = res.headers.get("Content-Type"); if (typeof contentType !== "string") { return res;