Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retry callback #359

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: retry callback #359

wants to merge 5 commits into from

Conversation

enkot
Copy link

@enkot enkot commented Feb 5, 2024

πŸ”— Linked issue

#358

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds support for a callback for retry option, which is a function that takes a fetch context object and count of retries and returns a boolean (true if the request needs to be retried):

await $fetch('/cart', {
  retry: (ctx, count) => {
    return count <= 3 && ctx.error?.code === '007'
  }
})

It runs onError and after a response, so the developer can decide when the request needs to be retried.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@gustavopch
Copy link

My 2 cents: shouldRetry seems to better describe what this does.

@enkot
Copy link
Author

enkot commented Mar 7, 2024

@pi0 Could you please check? I think it's a really flexible solution.

@cernymatej
Copy link

I love this idea. Probably link my issue as well as this should cover that use case too: #355

@AryanShrivastava18
Copy link

@enkot By when can we expect this change to be the part of the release? Is there anything I can give a support for to push it to release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants