owmweather: Handle possible exceptions and make conditional shorter. Rewrite the comment in the ChangeLog

pull/3387/head
gsuarezc 2024-04-27 22:50:28 +01:00
parent 7f5d375f29
commit 1832f20936
2 changed files with 7 additions and 4 deletions

View File

@ -3,4 +3,4 @@
0.03: Fix updating weather too often
0.04: Minor code improvements
0.05: Upgrade OWM to One Call API 3.0. Add pressure to weather.json
0.06: Fix One Call API 3.0 does not return city name but it is required by weather app
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app

View File

@ -1,7 +1,10 @@
function parseWeather(response) {
let owmData = JSON.parse(response);
let isOwmData = (owmData.lat && owmData.lon) && owmData.current.weather && owmData.current;
let isOwmData = false;
try {
isOwmData = (owmData.lat && owmData.lon) && owmData.current.weather && owmData.current;
} catch (_e) {}
if (isOwmData) {
let json = require("Storage").readJSON('weather.json') || {};
@ -12,9 +15,9 @@ function parseWeather(response) {
weather.code = owmData.current.weather[0].id;
weather.wdir = owmData.current.wind_deg;
weather.wind = owmData.current.wind_speed;
weather.loc = owmData.name ? owmData.name : "";
weather.loc = owmData.name || "";
weather.txt = owmData.current.weather[0].main;
weather.hpa = owmData.current.pressure ? owmData.current.pressure : 0;
weather.hpa = owmData.current.pressure || 0;
if (weather.wdir != null) {
let deg = weather.wdir;