UNPKG

@tanstack/offline-transactions

Version:

Offline-first transaction capabilities for TanStack DB

34 lines (33 loc) 931 B
import { NonRetriableError } from "../types.js"; import { BackoffCalculator } from "./BackoffCalculator.js"; class DefaultRetryPolicy { constructor(maxRetries = Number.POSITIVE_INFINITY, jitter = true) { this.backoffCalculator = new BackoffCalculator(jitter); this.maxRetries = maxRetries; } calculateDelay(retryCount) { return this.backoffCalculator.calculate(retryCount); } shouldRetry(error, retryCount) { if (retryCount >= this.maxRetries) { return false; } if (error instanceof NonRetriableError) { return false; } if (error.name === `AbortError`) { return false; } if (error.message.includes(`401`) || error.message.includes(`403`)) { return false; } if (error.message.includes(`422`) || error.message.includes(`400`)) { return false; } return true; } } export { DefaultRetryPolicy }; //# sourceMappingURL=RetryPolicy.js.map