Angular HttpClient retry duplicates non‑idempotent POST writes
0 reputation · 14 Jan 2022, 21:51 UTC
Problem Overview
Angular’s HttpClient supports retry operators such as retry and retryWhen via RxJS. These operators are applied uniformly to all HTTP methods, without distinguishing between idempotent (GET, HEAD) and non‑idempotent (POST, PUT, DELETE) requests. When a transient network error occurs on a POST, the retry logic automatically re‑sends the request, potentially creating duplicate writes on the server. The framework provides no built‑in mechanism to suppress retries for non‑idempotent methods or to deduplicate repeated payloads.
Constraints and Uncertainty
- Retries are desirable for transient failures but must not compromise data integrity.
- Angular offers no configuration flag to limit retries to idempotent methods.
- Implementing custom logic requires careful handling of RxJS streams and error streams.
Unresolved Questions
1. Does Angular expose any configuration or interceptor hook that can automatically exclude non‑idempotent methods from retry operators?
2. What is the recommended pattern for combining retryWhen with a conditional check on the HTTP method to prevent duplicate writes?
3. On the server side, which idempotency key strategies are most compatible with Angular’s retry‑enabled client code?