Reputation: 73908
I am using dojo/request/notify
in order to globally detect errors when an issue with a Ajax callis found.
For calling an API I am using dojo/store/JsonRest
.
When requests have failed notify
works as expected but in case of timeout notify
does not work.
I need to detect timeout errors.
Upvotes: 0
Views: 364
Reputation: 73908
As it looks like that dojo does not offer this option out of the box.
I have thought the following solutions:
dojo/store/JsonRest
which pass a timeout
value.dojo/_base/xhr
.XMLHttpRequest
.I have chosen solution 3. here below a code example:
(function (xhr) {
var send = xhr.send;
xhr.send = function (data) {
this.timeout = 5000;
var hasTimeOut = 'ontimeout' in this;
if (hasTimeOut) {
this.ontimeout = function () {
throw ('Error XMLHttpRequest timeout.');
};
}
return send.apply(this, arguments);
};
})(XMLHttpRequest.prototype);
Upvotes: 1