Skip to content

Commit fcf132a

Browse files
authored
Merge pull request #110 from github/jonrohan-patch-1
2 parents 75ac8d9 + c7b1ca1 commit fcf132a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/include-fragment-element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ export class IncludeFragmentElement extends HTMLElement {
234234
try {
235235
await this.#task(['loadstart'])
236236
const response = await this.fetch(this.request())
237-
if (response.status !== 200) {
238-
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
239-
}
240237
const ct = response.headers.get('Content-Type')
241238
if (!isWildcard(this.accept) && (!ct || !ct.includes(this.accept ? this.accept : 'text/html'))) {
242239
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
243240
}
241+
if (response.status !== 200) {
242+
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
243+
}
244244

245245
const responseText: string = await response.text()
246246
let data: string | CSPTrustedHTMLToStringable = responseText

test/test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ suite('include-fragment-element', function () {
213213
await el.data
214214
throw new Error('el.data did not throw')
215215
} catch (error) {
216-
assert.match(error, /the server responded with a status of 406/)
216+
assert.match(error, /expected text\/html but was text\/plain/)
217217
}
218218
})
219219

@@ -343,7 +343,10 @@ suite('include-fragment-element', function () {
343343
assert.equal(event.bubbles, false)
344344
assert.equal(event.cancelable, false)
345345
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')
346+
assert.equal(
347+
event.detail.error.message,
348+
'Failed to load resource: expected text/html but was text/plain;charset=UTF-8',
349+
)
347350
})
348351

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

0 commit comments

Comments
 (0)