* Fetch remote settings with retry logic and exponential backoff * Uses existing codebase retry utilities for consistency
( cachedChecksum?: string, )
| 207 | * Uses existing codebase retry utilities for consistency |
| 208 | */ |
| 209 | async function fetchWithRetry( |
| 210 | cachedChecksum?: string, |
| 211 | ): Promise<RemoteManagedSettingsFetchResult> { |
| 212 | let lastResult: RemoteManagedSettingsFetchResult | null = null |
| 213 | |
| 214 | for (let attempt = 1; attempt <= DEFAULT_MAX_RETRIES + 1; attempt++) { |
| 215 | lastResult = await fetchRemoteManagedSettings(cachedChecksum) |
| 216 | |
| 217 | // Return immediately on success |
| 218 | if (lastResult.success) { |
| 219 | return lastResult |
| 220 | } |
| 221 | |
| 222 | // Don't retry if the error is not retryable (e.g., auth errors) |
| 223 | if (lastResult.skipRetry) { |
| 224 | return lastResult |
| 225 | } |
| 226 | |
| 227 | // If we've exhausted retries, return the last error |
| 228 | if (attempt > DEFAULT_MAX_RETRIES) { |
| 229 | return lastResult |
| 230 | } |
| 231 | |
| 232 | // Calculate delay and wait before next retry |
| 233 | const delayMs = getRetryDelay(attempt) |
| 234 | logForDebugging( |
| 235 | `Remote settings: Retry ${attempt}/${DEFAULT_MAX_RETRIES} after ${delayMs}ms`, |
| 236 | ) |
| 237 | await sleep(delayMs) |
| 238 | } |
| 239 | |
| 240 | // Should never reach here, but TypeScript needs it |
| 241 | return lastResult! |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Fetch the full remote settings (single attempt, no retries) |
no test coverage detected