From 1ca48343e8f1493f068b4559bde2300a9078aa52 Mon Sep 17 00:00:00 2001 From: infodusha Date: Sun, 28 Jul 2024 21:01:22 +0300 Subject: [PATCH] feat(runtime): handle load errors --- src/css-helpers.ts | 4 ++-- src/index.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/css-helpers.ts b/src/css-helpers.ts index 43c5e52..1611d19 100644 --- a/src/css-helpers.ts +++ b/src/css-helpers.ts @@ -5,7 +5,7 @@ const hostRe = /:host(\((.+)\))?/g; export function getEncapsulatedCss( template: HTMLTemplateElement, style: HTMLStyleElement, - selector: string, + selector: string ): string { const unique = `data-${selector}-css`; if (!style.sheet) { @@ -18,7 +18,7 @@ export function getEncapsulatedCss( continue; } for (const element of template.content.querySelectorAll( - rule.selectorText, + rule.selectorText )) { element.setAttribute(unique, ""); } diff --git a/src/index.ts b/src/index.ts index 5b34cb7..7f6cf1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,9 @@ async function fetchFromLinks(): Promise { async function defineHtml(link: HTMLLinkElement): Promise { const href = returnIfDefined(link.getAttribute("href")); - const response = await fetch(href); + const response = await fetch(href).catch((err) => { + throw new Error(`Unable to load ${href}`, { cause: err }); + }); const text = await response.text(); const definedElement = parser.parseFromString(text, "text/html"); customElements.define(...createComponent(definedElement, href));