Improve "Load more" error handling in feeds (#379)

* Add explicit load-more error handling to posts feed

* Add explicit load-more error handling to notifications feed

* Properly set hasMore to false after an error
This commit is contained in:
Paul Frazee 2023-04-03 15:57:17 -05:00 committed by GitHub
parent 2045c615a8
commit b12cd53a4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 159 additions and 33 deletions

View file

@ -213,6 +213,7 @@ export class PostsFeedModel {
hasNewLatest = false
hasLoaded = false
error = ''
loadMoreError = ''
params: GetTimeline.QueryParams | GetAuthorFeed.QueryParams
hasMore = true
loadMoreCursor: string | undefined
@ -382,18 +383,25 @@ export class PostsFeedModel {
await this._appendAll(res)
this._xIdle()
} catch (e: any) {
this._xIdle() // don't bubble the error to the user
this.rootStore.log.error('FeedView: Failed to load more', {
params: this.params,
e,
this._xIdle(undefined, e)
runInAction(() => {
this.hasMore = false
})
this.hasMore = false
}
} finally {
this.lock.release()
}
})
/**
* Attempt to load more again after a failure
*/
async retryLoadMore() {
this.loadMoreError = ''
this.hasMore = true
return this.loadMore()
}
/**
* Update content in-place
*/
@ -503,13 +511,20 @@ export class PostsFeedModel {
this.error = ''
}
_xIdle(err?: any) {
_xIdle(error?: any, loadMoreError?: any) {
this.isLoading = false
this.isRefreshing = false
this.hasLoaded = true
this.error = cleanError(err)
if (err) {
this.rootStore.log.error('Posts feed request failed', err)
this.error = cleanError(error)
this.loadMoreError = cleanError(loadMoreError)
if (error) {
this.rootStore.log.error('Posts feed request failed', error)
}
if (loadMoreError) {
this.rootStore.log.error(
'Posts feed load-more request failed',
loadMoreError,
)
}
}