elbywan / wretch-middlewares

Collection of middlewares for the Wretch library. 🎁
MIT License
47 stars 7 forks source link

Retry while user is offline #2

Closed thibautguedou3 closed 5 years ago

thibautguedou3 commented 5 years ago

I am trying to implement a use case when a user performs a request without internet. When I use the retry middleware, the retry is not called if the user isOffline. How would you implement it?

elbywan commented 5 years ago

Hey @thibautguedou3,

I just published a new version (0.1.8) of the package that now contains the feature, thanks for the suggestion 👍!

Basically, there is a new retryOnNetworkError boolean option.

If you set it to true, when fetch throws because of a network error: 1) With the default options the request will be retried 2) You will have access to an extra error argument in the until and onRetry methods

Hope this will suit your needs!