From 3b080fa3331751f0edde1c18251732f8d1498884 Mon Sep 17 00:00:00 2001
From: Philipp Stadler <hello@phstadler.com>
Date: Mon, 29 Jul 2024 19:00:39 +0200
Subject: [PATCH] chore: add error handler also for second waiters

---
 src/components/data.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/components/data.ts b/src/components/data.ts
index 5b2dca1..c2db5c6 100644
--- a/src/components/data.ts
+++ b/src/components/data.ts
@@ -116,9 +116,13 @@ async function fetchJsonp (opts: GetDataOpts): Promise<Readonly<unknown>> {
       // For testing in parcel it works better to have a subpath that we can
       // exclude from parcel.
       : `/${process.env.BUILD_PREFIX}${opts.path}`
-    if (document.querySelector(`script[src="${url}"]`) !== null) {
+    const existingScript = document.querySelector(`script[src="${url}"]`)
+    if (existingScript !== null) {
       // already being fetched, append to the list of existing waiters
       registerJsonpWaiter(opts.key, resolve)
+      existingScript.addEventListener('error', () => {
+        reject(new Error(`No character data available for ${opts.key}`))
+      })
     } else {
       // no fetch in flight, inject a new script tag
       const script = document.createElement('script')
-- 
GitLab