infinite-scroll icon indicating copy to clipboard operation
infinite-scroll copied to clipboard

"Last" event does not work with an 204 status response

Open GrupoDO opened this issue 3 years ago • 1 comments

Hello!

The last event does not work with HTTP 204 status response. You can see in https://conocien.do/hallstatt/actividades the loading text remains visible.

Checking the source code the problem seems to be in the block:

let fetchPromise = fetch( path, fetchOptions )
    .then( ( response ) => {
      if ( !response.ok ) {
        let error = new Error( response.statusText );
        this.onPageError( error, path, response );
        return { response };
      }
      return response[ responseBody ]().then( ( body ) => {
    	  console.log(body);
        let canDomParse = responseBody == 'text' && domParseResponse;
        if ( canDomParse ) {
          body = domParser.parseFromString( body, 'text/html' );
        }
      
        if ( response.status == 204 ) {
          this.lastPageReached( body, path );
          return { body, response };
        } else {
          return this.onPageLoad( body, path, response );
        }
      } );
    } )
    .catch( ( error ) => {
    	console.log(error);
      this.onPageError( error, path );
    } );

A status 204 never returns content, it's an empty body response, so the code never enters into "response responseBody .then" and it's catched with the error "SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data"

Can you check this bug, please?

Thank you!

GrupoDO avatar Jul 22 '21 13:07 GrupoDO

same issue here. by definition, if HTTP response code is 204, it cannot contain body. the code in fetchPromise is incorrect.

temuri416 avatar Sep 13 '21 19:09 temuri416