[owmweather] create more explicit errorCallback function
parent
d5453990fd
commit
7cc837d595
|
|
@ -7,3 +7,4 @@
|
|||
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
|
||||
0.08: Undo change to One Call API 3.0
|
||||
0.09: Fix infinite loop when settings.updated is not defined
|
||||
0.10: Fix settings.updated being updated even when OWM call failed
|
||||
|
|
@ -12,12 +12,15 @@
|
|||
|
||||
let onCompleted = function (result) {
|
||||
loading = false;
|
||||
if(typeof result === "string") {
|
||||
console.log("owmweather error: " + result);
|
||||
} else {
|
||||
settings.updated = Date.now();
|
||||
require('Storage').writeJSON("owmweather.json", settings);
|
||||
}
|
||||
if (timeoutRef) clearTimeout(timeoutRef);
|
||||
timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis());
|
||||
};
|
||||
|
||||
let onError = function(e) {
|
||||
console.log("owmweather error:", e);
|
||||
loading = false;
|
||||
if (timeoutRef) clearTimeout(timeoutRef);
|
||||
timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis());
|
||||
};
|
||||
|
|
@ -34,7 +37,7 @@
|
|||
if (!MillisUntilDue || MillisUntilDue <= 0) {
|
||||
if (!loading) {
|
||||
loading = true;
|
||||
require("owmweather").pull(onCompleted);
|
||||
require("owmweather").pull(onCompleted, onError);
|
||||
}
|
||||
} else {
|
||||
// called to early, reschedule
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ function parseWeather(response) {
|
|||
}
|
||||
}
|
||||
|
||||
exports.pull = function(completionCallback) {
|
||||
exports.pull = function(completionCallback, errorCallback) {
|
||||
let location = require("Storage").readJSON("mylocation.json", 1) || {
|
||||
"lat": 51.50,
|
||||
"lon": 0.12,
|
||||
|
|
@ -46,9 +46,9 @@ exports.pull = function(completionCallback) {
|
|||
let result = parseWeather(event.resp);
|
||||
if (completionCallback) completionCallback(result);
|
||||
}).catch((e)=>{
|
||||
if (completionCallback) completionCallback(e);
|
||||
if (errorCallback) errorCallback(e);
|
||||
});
|
||||
} else {
|
||||
if (completionCallback) completionCallback(/*LANG*/"No http method found");
|
||||
if (errorCallback) errorCallback(/*LANG*/"No http method found");
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{ "id": "owmweather",
|
||||
"name": "OpenWeatherMap weather provider",
|
||||
"shortName":"OWM Weather",
|
||||
"version": "0.09",
|
||||
"version": "0.10",
|
||||
"description": "Pulls weather from OpenWeatherMap (OWM) API",
|
||||
"icon": "app.png",
|
||||
"type": "bootloader",
|
||||
|
|
|
|||
Loading…
Reference in New Issue