[#448] added reconnection logic to websocket (#472)

* [#448] added reconnection logic to websocket

* [#448] added test

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Camille Moussu
2026-01-27 14:54:03 +01:00
committed by GitHub
parent d966a9eb2f
commit 83fae6f1c2
6 changed files with 1007 additions and 24 deletions
+6 -9
View File
@@ -1,25 +1,22 @@
import { Auth } from "@/features/User/oidcAuth";
import ky from "ky";
import { getRetryDelay } from "./getRetryDelay";
const RETRY_CONFIG = {
maxRetries: 10,
initialDelay: 1000,
maxDelay: 120000,
};
function getRetryDelay(attemptNumber: number): number {
const cap = RETRY_CONFIG.maxDelay;
const base = RETRY_CONFIG.initialDelay * Math.pow(2, attemptNumber);
const jitter = 0.5 + Math.random();
return Math.min(cap, base * jitter);
}
export const api = ky.extend({
prefixUrl: (window as any).CALENDAR_BASE_URL,
retry: {
limit: RETRY_CONFIG.maxRetries,
backoffLimit: RETRY_CONFIG.maxDelay,
delay: (attemptCount) => getRetryDelay(attemptCount - 1),
delay: (attemptCount) =>
getRetryDelay(attemptCount - 1, {
initialDelay: RETRY_CONFIG.initialDelay,
maxDelay: RETRY_CONFIG.maxDelay,
}),
},
hooks: {
beforeRequest: [