connor4312 / cockatiel

🐦 A resilience and fault-handling library. Supports Backoffs, Retries, Circuit Breakers, Timeouts, Bulkhead Isolation, and Fallbacks.
MIT License
1.59k stars 50 forks source link

Feature Idea / Request: Configure Retry Policy to throw RetryAttemptsExhausted Error instead of returning last error / result #38

Closed mmadson closed 3 years ago

mmadson commented 3 years ago

I'd like to know when the configured retry attempts have been exhausted. Currently the only way for me to do this is by registering on onGiveUp event emitter but this has the drawback of having to dispose of the listener. Would much prefer I could configure the retry policy to throw for me rather than exhausting the attempts and silently returning the last result.

connor4312 commented 3 years ago

Throwing a RetryAttemptsExhausted error would require callers to add handling for that, it seems you could (if extra handling is needed anyway) handle the underlying error or errorful result. E.g. if you retry on a DatabaseNotAvailable error, handle that if it bubbles up from the retry.