64. auto-retry Promise on rejection

JavaScript
Is this helpful ?

medium  - accepted / - tried

For a web application, fetching API data is a common task.

But the API calls might fail because of Network problems. Usually we could show a screen for Network Error and ask users to retry.

One approach to handle this is auto retry when network error occurs.

You are asked to create a fetchWithAutoRetry(fetcher, count), which automatically fetch again when error happens, until the maximum count is met.

For the problem here, there is no need to detect network error, you can just retry on all promise rejections.

Let's try to solve this problem within 10 mintues.

Discuss(38)