Non-throw Mode
Set throwOnExhausted false to receive a RetryRunResult instead of a thrown error.
throwOnExhausted: false returns a RetryRunResult instead of throwing.
const result = await runRetryPolicy(
policy,
async () => {
return await doWork();
},
{ throwOnExhausted: false },
);
if (result.ok) {
console.log(result.value);
} else {
console.error("Failed after", result.attempts, "attempts:", result.error);
}
On failure, result.error is a RetryError (retries exhausted, or a caught value the policy’s isKnownError rejected as outside its error domain) or an AbortError (run canceled).
Aborting a run behaves the same way in this mode — see Cancellation.
See Also
- Shared Runner — the default throw mode
- Structured Errors — the
RetryErrorandAbortErrorshapes