Skip to content

Commit

Permalink
fix 403 Network Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Jan 3, 2021
1 parent 5cfdedf commit 370f786
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
42 changes: 23 additions & 19 deletions dist/infinite-scroll.pkgd.js
@@ -1,5 +1,5 @@
/*!
* Infinite Scroll PACKAGED v4.0.0
* Infinite Scroll PACKAGED v4.0.1
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down Expand Up @@ -844,26 +844,30 @@ proto.loadNextPage = function() {
this.isLoading = true;
if ( typeof fetchOptions == 'function' ) fetchOptions = fetchOptions();

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 ) => {
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 );
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 ) => {
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 ) => {
this.onPageError( error, path );
} );
} );

this.dispatchEvent( 'request', null, [ path, fetchPromise ] );

Expand Down
4 changes: 2 additions & 2 deletions dist/infinite-scroll.pkgd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/index.js
@@ -1,5 +1,5 @@
/*!
* Infinite Scroll v4.0.0
* Infinite Scroll v4.0.1
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "infinite-scroll",
"version": "4.0.0",
"version": "4.0.1",
"description": "Automatically add next page",
"main": "js/index.js",
"files": [
Expand Down

0 comments on commit 370f786

Please sign in to comment.