I have a method that fetches some data from an API.
$http.get("https://httpstat.us/200?sleep=20000", header).then(
function successCallback(response) {
//logic
},
function errorCallback(response) {
}
);
In certain test cases, the API takes forever to respond so I need a way to handle such cases. If the API is taking more than 10 seconds, I need to return some data. I tried adding a timeout to the request using the code below
$http.get("https://httpstat.us/200?sleep=20000", {timeout: 10000}).then(
But this just aborts the request and goes to the error callback. Is there another way to know if the request is taking forever to respond without actually timing out the request?