Skip to content
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 @@ -234,13 +234,13 @@ export class IncludeFragmentElement extends HTMLElement {
try {
await this.#task(['loadstart'])
const response = await this.fetch(this.request())
if (response.status !== 200) {
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
}
const ct = response.headers.get('Content-Type')
if (!isWildcard(this.accept) && (!ct || !ct.includes(this.accept ? this.accept : 'text/html'))) {
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
}
if (response.status !== 200) {
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
}

const responseText: string = await response.text()
let data: string | CSPTrustedHTMLToStringable = responseText
Expand Down
7 changes: 5 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ suite('include-fragment-element', function () {
await el.data
throw new Error('el.data did not throw')
} catch (error) {
assert.match(error, /the server responded with a status of 406/)
assert.match(error, /expected text\/html but was text\/plain/)
}
})

Expand Down Expand Up @@ -343,7 +343,10 @@ suite('include-fragment-element', function () {
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')
assert.equal(
event.detail.error.message,
'Failed to load resource: expected text/html but was text/plain;charset=UTF-8',
)
})

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