Skip to content

Commit 75ac8d9

Browse files
authored
Merge pull request #108 from github/manuelpuyol-patch-1
Send error information to event
2 parents 4254978 + 45014a6 commit 75ac8d9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/include-fragment-element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ export class IncludeFragmentElement extends HTMLElement {
220220
}
221221

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

@@ -258,7 +258,7 @@ export class IncludeFragmentElement extends HTMLElement {
258258
// Dispatch `error` and `loadend` async to allow
259259
// the `load()` promise to resolve _before_ these
260260
// events are fired.
261-
this.#task(['error', 'loadend'])
261+
this.#task(['error', 'loadend'], error as Error)
262262
throw error
263263
}
264264
}

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ suite('include-fragment-element', function () {
342342
const event = await when(div.firstChild, 'error')
343343
assert.equal(event.bubbles, false)
344344
assert.equal(event.cancelable, false)
345+
assert.instanceOf(event.detail.error, Error)
346+
assert.equal(event.detail.error.message, 'Failed to load resource: the server responded with a status of 500')
345347
})
346348

347349
test('adds is-error class on 500 status', async function () {

0 commit comments

Comments
 (0)