-
Notifications
You must be signed in to change notification settings - Fork 226
[FIX] many-request-error #571
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,15 +162,38 @@ export const loadMessages = async () => { | |
| } | ||
|
|
||
| await store.setState({ loading: true }); | ||
| const rawMessages = (await Livechat.loadMessages(rid)).concat(previousMessages); | ||
| const messages = (await normalizeMessages(rawMessages)).map(transformAgentInformationOnMessage); | ||
|
|
||
| await initRoom(); | ||
| await store.setState({ messages: (messages || []).reverse(), noMoreMessages: false, loading: false }); | ||
|
|
||
| if (messages && messages.length) { | ||
| const lastMessage = messages[messages.length - 1]; | ||
| await store.setState({ lastReadMessageId: lastMessage && lastMessage._id }); | ||
| try { | ||
| const rawMessages = (await Livechat.loadMessages(rid)).concat(previousMessages); | ||
| const messages = (await normalizeMessages(rawMessages)).map(transformAgentInformationOnMessage); | ||
| await initRoom(); | ||
| await store.setState({ messages: (messages || []).reverse(), noMoreMessages: false, loading: false }); | ||
|
|
||
| if (messages && messages.length) { | ||
| const lastMessage = messages[messages.length - 1]; | ||
| await store.setState({ lastReadMessageId: lastMessage && lastMessage._id }); | ||
| } | ||
| } | ||
| catch(e) { | ||
| const waitTime = parseInt(e.data.error.match(/^.*You must wait ([0-9]*) seconds.*$/)[1]); | ||
| const decrementCounter = async () => { | ||
| if(window.loadMessagesTimeout) { | ||
| clearInterval(window.loadMessagesTimeout); | ||
| } | ||
| window.loadMessagesTimeout = setInterval(() => { | ||
| let tmpWaitTime = store.state.loadWaitTime; | ||
| if(tmpWaitTime) { | ||
| store.setState({loadWaitTime: tmpWaitTime - 1, loadingMessage: `Error, too many requests. Please slow down. You must wait for ${tmpWaitTime} seconds.` }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please set this message on i18n files.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to your comment, does I need to set that message in all i18n files. Like I have to translate that message to all other languages and set it to respective i18n json files. Right? And if this is the case how I can identify which i18n json file belong to which language. Is there any fast way to do this or I have to manually check each i18n json file to check which language it belongs to. Looking forward to your response. Thanks.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check the You'll use with |
||
| } | ||
| else { | ||
| if(window.loadMessagesTimeout) { | ||
| clearInterval(window.loadMessagesTimeout); | ||
| } | ||
| window.location.reload(); | ||
| } | ||
| }, 1000) | ||
| } | ||
| await store.setState({ loading: true, loadWaitTime: waitTime }); | ||
| await decrementCounter(); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please set this message on i18n files.