Skip to content

Send error information to event #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/include-fragment-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ export class IncludeFragmentElement extends HTMLElement {
}

// Functional stand in for the W3 spec "queue a task" paradigm
async #task(eventsToDispatch: string[]): Promise<void> {
async #task(eventsToDispatch: string[], error?: Error): Promise<void> {
await new Promise(resolve => setTimeout(resolve, 0))
for (const eventType of eventsToDispatch) {
this.dispatchEvent(new Event(eventType))
this.dispatchEvent(error ? new CustomEvent(eventType, {detail: {error}}) : new Event(eventType))
}
}

Expand Down Expand Up @@ -258,7 +258,7 @@ export class IncludeFragmentElement extends HTMLElement {
// Dispatch `error` and `loadend` async to allow
// the `load()` promise to resolve _before_ these
// events are fired.
this.#task(['error', 'loadend'])
this.#task(['error', 'loadend'], error as Error)
throw error
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ suite('include-fragment-element', function () {
const event = await when(div.firstChild, 'error')
assert.equal(event.bubbles, false)
assert.equal(event.cancelable, false)
assert.instanceOf(event.detail.error, Error)
assert.equal(event.detail.error.message, 'Failed to load resource: the server responded with a status of 500')
})

test('adds is-error class on 500 status', async function () {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy