DEV Community

Discussion on: Axios Async/Await with Retry

Collapse
 
bikamdhakal profile image
bikamdhakal

How to implement such functionality on post request
For example: User hits a login button it will send post request but during hitting that button the internet is low or off, after certain time if the internet is on that api needed to called automatically when the internet gets on.

Collapse
 
yogski profile image
Yogi Saputro

You can wrap the POST request as usual, then adjust the timeout accordingly. If the network is unstable, set timeout to 3 seconds (3000 in code) and set retry to 3-5 times. If login is successful, user will be redirected immediately. If it failed, throw notification that login failed due to network issue, and user can try to log in again.

Be warned that it has trade-off of higher traffic for server.
Find the best configuration between timeout and retries that suit your needs.