From 2e124db4cb559a945a4334b47d6de66fb78fc1c0 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 5 Jul 2026 19:31:41 -0400 Subject: [PATCH] Retry Open Meteo API when overloaded --- src/pkjs/weather.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/pkjs/weather.js b/src/pkjs/weather.js index 4ebfcaf..64dff2e 100644 --- a/src/pkjs/weather.js +++ b/src/pkjs/weather.js @@ -2,14 +2,27 @@ function weatherFailure() { 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(); xhr.timeout = 7500; xhr.onload = function () { - if (xhr.status === 200) { - callback(this.responseText); - } else { - weatherFailure(); + switch (xhr.status) { + case 200: + callback(this.responseText); + break; + case 503: + if (retries > 0) { + setTimeout(function () { + xhrRequest(url, type, callback, retries - 1); + }, 5000); + break; + } + // fallthrough + default: + weatherFailure(); } }; xhr.onerror = function () {