Question

It seems the status code is 404 for both timed out requests and for Not found.

What is the best way to check if the request failed because of a spotty connection (and eventually retry the request) in angular?

Was it helpful?

Solution

I don't get a 404 for timeouts.

Just ran this code

$http({ method: "GET", url: "http://localhost:4789/foo", timeout: 5000})
    .then(
    function () {
        console.log("all OK");
    },
    function (response) {
        console.log(response);
    });

against a URL that busy waits. After 5 seconds, the failure callback of the $http promise fires with response:

Object {data: null, status: 0, headers: function, config: Object}

The status is 0, not 404. Chrome's Network tab shows the request as "(cancelled)".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top