Adding a reconnect feature in case first Pusher request fails
Now, if the first pusher request fails, a waiting message will be displayed and the application will reconnect when the pusher comes back alive or the network connection is established again.
This commit is contained in:
parent
9eb4206fe0
commit
fcf0888864
17 changed files with 981 additions and 32 deletions
37
front/src/Connexion/AxiosUtils.ts
Normal file
37
front/src/Connexion/AxiosUtils.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import axios from "axios";
|
||||
import * as rax from "retry-axios";
|
||||
import {errorStore} from "../Stores/ErrorStore";
|
||||
|
||||
/**
|
||||
* This instance of Axios will retry in case of an issue and display an error message as a HTML overlay.
|
||||
*/
|
||||
export const axiosWithRetry = axios.create();
|
||||
axiosWithRetry.defaults.raxConfig = {
|
||||
instance: axiosWithRetry,
|
||||
retry: Infinity,
|
||||
noResponseRetries: Infinity,
|
||||
|
||||
maxRetryAfter: 60_000,
|
||||
|
||||
// You can detect when a retry is happening, and figure out how many
|
||||
// retry attempts have been made
|
||||
onRetryAttempt: err => {
|
||||
const cfg = rax.getConfig(err);
|
||||
console.log(err)
|
||||
console.log(cfg)
|
||||
console.log(`Retry attempt #${cfg?.currentRetryAttempt}`);
|
||||
errorStore.addErrorMessage('Unable to connect to WorkAdventure. Are you connected to internet?', {
|
||||
closable: false,
|
||||
id: "axios_retry"
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
axiosWithRetry.interceptors.response.use(res => {
|
||||
if (res.status < 400) {
|
||||
errorStore.clearMessageById("axios_retry");
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
const interceptorId = rax.attach(axiosWithRetry);
|
Loading…
Add table
Add a link
Reference in a new issue