Skip to content

Commit 62642dc

Browse files
authored
Move content type check before general status !== 200
1 parent 207257b commit 62642dc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/include-fragment-element.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ export class IncludeFragmentElement extends HTMLElement {
234234
try {
235235
await this.#task(['loadstart'])
236236
const response = await this.fetch(this.request())
237+
const ct = response.headers.get('Content-Type')
238+
if (!isWildcard(this.accept) && (!ct || !ct.includes(this.accept ? this.accept : 'text/html'))) {
239+
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
240+
}
237241
if (response.status !== 200) {
238242
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
239243
}
@@ -255,10 +259,6 @@ export class IncludeFragmentElement extends HTMLElement {
255259
// the `load()` promise to resolve _before_ these
256260
// events are fired.
257261
this.#task(['error', 'loadend'], error as Error)
258-
const ct = response.headers.get('Content-Type')
259-
if (!isWildcard(this.accept) && (!ct || !ct.includes(this.accept ? this.accept : 'text/html'))) {
260-
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
261-
}
262262
throw error
263263
}
264264
}

0 commit comments

Comments
 (0)