File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 , / t h e s e r v e r r e s p o n d e d w i t h a s t a t u s o f 4 0 6 / )
216+ assert . match ( error , / e x p e c t e d t e x t \/ h t m l b u t w a s t e x t \/ p l a i n / )
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 ( ) {
You can’t perform that action at this time.
0 commit comments