[owmweather] simplify error handling
parent
34a4d354cf
commit
bd047f31f8
|
|
@ -27,9 +27,8 @@ function parseWeather(response) {
|
||||||
json.weather = weather;
|
json.weather = weather;
|
||||||
require("Storage").writeJSON('weather.json', json);
|
require("Storage").writeJSON('weather.json', json);
|
||||||
if (require("Storage").read("weather")!==undefined) require("weather").emit("update", json.weather);
|
if (require("Storage").read("weather")!==undefined) require("weather").emit("update", json.weather);
|
||||||
return undefined;
|
|
||||||
} else {
|
} 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;
|
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){
|
if (Bangle.http){
|
||||||
Bangle.http(uri, {timeout:10000}).then(event => {
|
Bangle.http(uri, {timeout:10000}).then(event => {
|
||||||
let result = parseWeather(event.resp);
|
parseWeather(event.resp);
|
||||||
if (result === undefined) {
|
if (completionCallback) completionCallback();
|
||||||
if (completionCallback) completionCallback();
|
|
||||||
} else {
|
|
||||||
if (errorCallback) errorCallback(result);
|
|
||||||
}
|
|
||||||
}).catch((e)=>{
|
}).catch((e)=>{
|
||||||
if (errorCallback) errorCallback(e);
|
if (errorCallback) errorCallback(e);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue