DEV Community

kreuzerk
kreuzerk

Posted on • Originally published at blog.angularindepth.com on

Retry failed HTTP requests in Angular

Immediate retry, delayed retry and retry with backoff

Accessing data from a backend is the backbone of almost every single page application. All dynamic content is loaded from a server.

In most cases, those HTTP requests work well and return the desired result. However, there are scenarios where a request might go wrong.

Imagine somebody is using your website over a hotspot on a train that rushes with 200 km/h across the country. ๐Ÿš… Well, the network might be slow, and the HTTP request still returns the desired result.

But what if the train enters a tunnel? The chances are high that the user has lost connection and your web app is unable to reach the server. In this case, the user is forced to refresh your application once he exits the tunnel and is back online.

Refreshing the application can have an impact on the current state of the application. The user could, for example, lose data he entered in a form.

Instead of letting a request instantly fail, it would be better to retry it a couple of times and display a corresponding message to the user. With such an approach, a refresh can be prevented.

Find out more...

Top comments (0)