diff --git a/CHANGELOG.md b/CHANGELOG.md index dec7ed014..8948cf58d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [3.3.2](https://github.com/GetStream/stream-chat-react/releases/tag/v3.3.2) 2020-12-11 + +## Fix + +- Add error handling for `loadMoreThread` API request [#627](https://github.com/GetStream/stream-chat-react/pull/627) + ## [3.3.1](https://github.com/GetStream/stream-chat-react/releases/tag/v3.3.1) 2020-12-9 ## Fix diff --git a/src/components/Channel/Channel.js b/src/components/Channel/Channel.js index 9aaea101c..09801ecd5 100644 --- a/src/components/Channel/Channel.js +++ b/src/components/Channel/Channel.js @@ -488,20 +488,25 @@ const ChannelInner = ({ dispatch({ type: 'closeThread' }); return; } + const oldMessages = channel.state.threads[parentID] || []; const oldestMessageID = oldMessages[0]?.id; const limit = 50; - const queryResponse = await channel.getReplies(parentID, { - limit, - id_lt: oldestMessageID, - }); - const threadHasMoreMessages = queryResponse.messages.length === limit; + try { + const queryResponse = await channel.getReplies(parentID, { + limit, + id_lt: oldestMessageID, + }); - const newThreadMessages = channel.state.threads[parentID] || []; + const threadHasMoreMessages = queryResponse.messages.length === limit; + const newThreadMessages = channel.state.threads[parentID] || []; - // next set loadingMore to false so we can start asking for more data... - loadMoreThreadFinished(threadHasMoreMessages, newThreadMessages); + // next set loadingMore to false so we can start asking for more data... + loadMoreThreadFinished(threadHasMoreMessages, newThreadMessages); + } catch (e) { + loadMoreThreadFinished(false, oldMessages); + } }, [channel, loadMoreThreadFinished, state.thread, state.threadLoadingMore]); const closeThread = useCallback((e) => {