From 11c7bfc8979d1379d861cebce12d61b57e1de2e3 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Fri, 15 Sep 2023 09:48:31 +0200 Subject: [PATCH] Add any error message from the weather datasource --- ipmd/static/ipmd/js/ipmdlib.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ipmd/static/ipmd/js/ipmdlib.js b/ipmd/static/ipmd/js/ipmdlib.js index 043717d4..402b9624 100644 --- a/ipmd/static/ipmd/js/ipmdlib.js +++ b/ipmd/static/ipmd/js/ipmdlib.js @@ -154,7 +154,17 @@ async function getStationWeatherData(endpoint, weatherStationId, parameters, int + "&weatherStationId=" + weatherStationId + "¶meters=" + parameters.join(",") ); - return await response.json(); + + if(response.status == 200) + { + return await response.json(); + } + else + { + let errorMessage = "No weather data was returned. Message from the data source was: \n\n" + await response.text(); + alert(errorMessage); + return null; + } } /** @@ -177,7 +187,18 @@ async function getLocationWeatherData(endpoint, longitude, latitude, parameters, + "&latitude=" + latitude + "¶meters=" + parameters.join(",") ); - return (response.status == 200) ? await response.json() : null; + + if(response.status == 200) + { + return await response.json(); + } + else + { + let errorMessage = "No weather data was returned. Message from the data source was: \n\n" + await response.text(); + alert(errorMessage); + return null; + } + } /** -- GitLab