vRetry
It used to retry some function based on certain condition. (usually used for retrying api requests)
import { vRetry } from "very-good-fetch";
const retry = new vRetry({
maxRetries: 3, // must be > 0
delay: 1000, // ms
onComplete: () => {
console.log("✅ Retry completed");
// logic...
},
retryCondition: (error) => {
console.log("📌 Retry if...", error);
return error?.status === 401;
},
});
const response = await retry.run(async () => {
try {
return await vFetch("/products/1", {
vOptions: {
responseType: "pure",
},
});
} catch (error) {
console.error(error);
}
});