[owmweather] simplify error handling

master
Logan B 2025-06-12 18:39:18 -05:00
parent 34a4d354cf
commit bd047f31f8
No known key found for this signature in database
1 changed files with 3 additions and 8 deletions

View File

@ -27,9 +27,8 @@ function parseWeather(response) {
json.weather = weather;
require("Storage").writeJSON('weather.json', json);
if (require("Storage").read("weather")!==undefined) require("weather").emit("update", json.weather);
return undefined;
} else {
return /*LANG*/"Not OWM data";
throw /*LANG*/"Not OWM data";
}
}
@ -43,12 +42,8 @@ exports.pull = function(completionCallback, errorCallback) {
let uri = "https://api.openweathermap.org/data/2.5/weather?lat=" + location.lat.toFixed(2) + "&lon=" + location.lon.toFixed(2) + "&exclude=hourly,daily&appid=" + settings.apikey;
if (Bangle.http){
Bangle.http(uri, {timeout:10000}).then(event => {
let result = parseWeather(event.resp);
if (result === undefined) {
if (completionCallback) completionCallback();
} else {
if (errorCallback) errorCallback(result);
}
parseWeather(event.resp);
if (completionCallback) completionCallback();
}).catch((e)=>{
if (errorCallback) errorCallback(e);
});