Custom retry logic
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 195
- PR merge metrics
- No merged PRs in 30d
Description
Describe the feature
Having a retry on specific status codes is great but could we get a more customizable way of getting a retry to happen? I think this is a common use case to retry a request if the response doest match criteria.
Now I need to do custom wrapper logic to get such functionality.
//custom wrapper
export async function retryCall<T>({
callback,
maxRetries = 5,
isResponseMatch,
delayMs = 1000,
}: {
maxRetries?: number;
isResponseMatch: (data: T) => boolean;
callback: () => Promise<T>;
delayMs?: number;
}): Promise<T> {
for (let attempt = 1; attempt < maxRetries; attempt++) {
try {
const response = await callback();
if (isResponseMatch(response)) {
return response;
}
} catch (error) {
throw error;
}
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
return await callback();
}
await retryCall({
callback: () => ofetch(...),
isResponseMatch: (data) => data === 'success',
})
Additional information
- Would you be willing to help implement this feature?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation files or tests; start by locating the existing retry handling and tests for status-code retries. Define the customizable response-matching behavior and its API, then add coverage showing that matching responses stop retries and nonmatching responses retry as configured.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100