ff77a18262
If a token decryption failed, it will emit a HTTP 500. We should not retry Axios in this case but rather fail. Note: a token decryption failed should not throw a HTTP 500 but another error code (HTTP 401?) So maybe this fix is plainly wrong.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
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,
|
|
|
|
statusCodesToRetry: [
|
|
[100, 199],
|
|
[429, 429],
|
|
[501, 599],
|
|
],
|
|
|
|
// 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} on URL '${err.config.url}'`);
|
|
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);
|