Error Retry

In applications, transient errors are actually very common. For example, the connection between the interface server and the database server is temporarily disconnected, or the user's network temporarily fails. These failures are often corrected by themselves in a short time. If you can try again after a suitable delay, the request may be successful.

Now you can let VueRequest handle this for you through a simple configuration. Just provide a errorRetryCount to tell us the number of retries. As the following example

ErrorRetryCount

import { useRequest } from 'vue-request';

const { data } = useRequest('api/users', {
  errorRetryCount: 5, // it will retry 5 times
});



 

ErrorRetryInterval

Tips

By default, we will use Exponential Backoff Algorithmopen in new window to help you calculate the appropriate interval time

Of course, you can also provide errorRetryInterval to set the retry interval

import { useRequest } from 'vue-request';

const { data } = useRequest('api/users', {
  errorRetryCount: 5, // it will retry 5 times
  errorRetryInterval: 3000, // The retry interval is 5 seconds
});




 

Last Updated: 2/11/2022, 8:31:25 AM
Contributors: John