Duplicate POST requests observed when enabling retries on $fetch in Nuxt 3
0 reputation · 25 Mar 2024, 01:24 UTC
Goal: Use the $fetch composable with a retry option to recover from transient network errors while guaranteeing that mutating HTTP requests (POST, PUT, PATCH) are not retried unless the backend endpoint is explicitly idempotent.
Constraint: Nuxt 3’s default retry mechanism applies only to GET, HEAD, and OPTIONS; setting retry to a number or true enables retries for all methods, and the supplied retry predicate receives only the error and response objects, not the original request method or URL. Developers must therefore manually inspect the method (e.g., via request options stored elsewhere) to block retries on unsafe calls, otherwise duplicate writes can occur.
Uncertainty: It is unclear whether a built‑in “safe‑retry” mode that automatically disables retries for non‑idempotent methods exists or is planned, and how to implement a reliable, low‑boilerplate guard that works globally across all $fetch invocations.
Is there a configuration or plugin that automatically disables retries for POST/PUT/PATCH unless explicitly opted‑in? How can a retry predicate safely determine the request method without accessing the original options? Does Nuxt provide a runtime hook or middleware to enforce safe‑retry behavior globally for all $fetch calls?