Retry Open Meteo API when overloaded
This commit is contained in:
+16
-3
@@ -2,13 +2,26 @@ function weatherFailure() {
|
|||||||
Pebble.sendAppMessage({ PKJS_TEMP_BAR_COUNT: -1 });
|
Pebble.sendAppMessage({ PKJS_TEMP_BAR_COUNT: -1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
var xhrRequest = function (url, type, callback) {
|
var xhrRequest = function (url, type, callback, retries) {
|
||||||
|
if (retries === undefined) {
|
||||||
|
retries = 2;
|
||||||
|
}
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.timeout = 7500;
|
xhr.timeout = 7500;
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
if (xhr.status === 200) {
|
switch (xhr.status) {
|
||||||
|
case 200:
|
||||||
callback(this.responseText);
|
callback(this.responseText);
|
||||||
} else {
|
break;
|
||||||
|
case 503:
|
||||||
|
if (retries > 0) {
|
||||||
|
setTimeout(function () {
|
||||||
|
xhrRequest(url, type, callback, retries - 1);
|
||||||
|
}, 5000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// fallthrough
|
||||||
|
default:
|
||||||
weatherFailure();
|
weatherFailure();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user