Skip to content

Retry request in interceptors response #170

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

Closed
nkovacic opened this issue Jan 31, 2020 · 7 comments
Closed

Retry request in interceptors response #170

nkovacic opened this issue Jan 31, 2020 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@nkovacic
Copy link

Usually servers handles token expiration and then with 401 response tells the client to refresh token.
In the examples this is handled in request interceptor, but is there a way to handle it response and retry all failed requests?

@iamthesiz
Copy link
Collaborator

The feature that you're looking for is on my todos
image

If you don't require having use-http manage all of your state, you can do

const attempts = useRef(3)
const [request, response] = useFetch({ path: '/whatever' })

const getUser = async () => {
  let data = await request.get()
  if (response.status === 401 && attempts.current > 0) {
    attempts.current--
    return await getUser()
  }
  return data
}

@iamthesiz
Copy link
Collaborator

@nkovacic does this help at all?

@nkovacic
Copy link
Author

nkovacic commented Feb 4, 2020

It could work this way, but currently opted for the client side check for token expiration, because currently its the only ways to do this in one place.

@iamthesiz
Copy link
Collaborator

I will try to get this implemented as soon as I can!

@iamthesiz iamthesiz added enhancement New feature or request help wanted Extra attention is needed labels Mar 10, 2020
@iamthesiz
Copy link
Collaborator

This feature is coming very soon! See this PR

@nkovacic
Copy link
Author

Great, thank you for your effort 👍

@iamthesiz
Copy link
Collaborator

@nkovacic This feature is implemented in v0.4.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants