This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$http timeout 408 #10081
Open
Description
I just used the timeout option in $http config cuz i thought it were taking to long for a simple get request to timeout on the server
$http.get("https://example.com", {
timeout: 10000
}).catch(function(res){
console.log(res.status); // 0
// Here I have no idea if it timed out cuz 0 is a undocumented status code it can mean more things
// I want to treat it the same as 408 (request timeout) as it came from the server
});
The usecase is to show a message depending on the code as in ng-switch on="res.status"
Instead i have to use $timeout and a promise instad of a simple integer and set the status code for myself
var timedout = false;
var timer = $timeout(function(){
timedout = true;
}, 10000);
$http.get("https://example.com", {
timeout: timer
}).catch(function(res){
if(timedout) res.status = 408
}).finaly(function(){
$timeout.cancel(timer);
});
Now a config with {timeout: promise}
can mean anything and be canceled for any reason like "not allowed to make so many request" or whatever. But with a {timeout: 10000}
we could assume it just timed out and we can set the status code to 408.
Would it make since to emulate 408 or don't we do any special treatment per request?
With simple xhr its much easier to tell if it timedout cuz you have the xhr.ontimeout event