Skip to content

Commit

Permalink
feat(runtime): handle load errors
Browse files Browse the repository at this point in the history
  • Loading branch information
infodusha committed Jul 28, 2024
1 parent 6212ef0 commit 1ca4834
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/css-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -18,7 +18,7 @@ export function getEncapsulatedCss(
continue;
}
for (const element of template.content.querySelectorAll(
rule.selectorText,
rule.selectorText
)) {
element.setAttribute(unique, "");
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ async function fetchFromLinks(): Promise<void> {

async function defineHtml(link: HTMLLinkElement): Promise<void> {
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));
Expand Down

0 comments on commit 1ca4834

Please sign in to comment.