From 619bba57c08918af7210a91368d9ef433b87559c Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Mon, 7 Oct 2024 16:27:23 -0400 Subject: [PATCH] Restore code body if val.town request fails --- packages/astro-md/middleware.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/astro-md/middleware.ts b/packages/astro-md/middleware.ts index 9d47069..02a6b04 100644 --- a/packages/astro-md/middleware.ts +++ b/packages/astro-md/middleware.ts @@ -74,6 +74,11 @@ class SyntaxHighlightRewriter implements HTMLRewriterElementContentHandlers { }, } ); + if (!res.ok) { + // Something went wrong with the request, just return the original code + text.replace(`${this.code}`, { html: true }); + return; + } const data = await res.text(); this.runtime.ctx.waitUntil(this.cache.put(key, data)); text.replace(data, { html: true });