[owmweather] simplify error handling
parent
34a4d354cf
commit
bd047f31f8
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue