1 import { RETRY_DELAY_MAX } from '@proton/shared/lib/constants';
2 import type { ApiError } from '@proton/shared/lib/fetch/ApiError';
3 import { wait } from '@proton/shared/lib/helpers/promise';
5 export const retryHandler = (e: ApiError, maxDelay = RETRY_DELAY_MAX) => {
6 const headers = e?.response?.headers;
8 const retryAfterSeconds = parseInt(headers?.get('retry-after') || '0', 10);
10 if (retryAfterSeconds < 0 || retryAfterSeconds >= maxDelay) {
11 return Promise.reject(e);
14 return wait(retryAfterSeconds * 1000);