marcusraitner / COVID-19-Dashboard

Dieses Scriptable-Skript erzeugt ein Widget, das den Verlauf der 7-Tage-Inzidenz und die Auslastung der Intensivbetten am aktuellen Standort anzeigt. Zusätzlich angezeigt wird der aktuelle Wert der 7-Tage-Inzidenz des zugehörigen Bundeslandes und der Impfstatus des Bundeslandes.
GNU General Public License v3.0
210 stars 16 forks source link

Widget shows error because hospitalization API returns error object #88

Open 0xbs opened 3 years ago

0xbs commented 3 years ago

Widget in version 1.10.0 shows an error message if used with vac=y:

Error on line 648:61: TypeError: undefined is not an object (evaluating 'hospitalizationData.data[bundesLand]")

Underlying issue is the API for hospitalization rates https://api.corona-zahlen.org/states which returns the following error:

{"error":{"message":"There is a problem with the official RKI API.","rkiError":{"code":400,"message":"","details":["Unable to perform query. Please check your parameters."]},"url":"https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_COVID19/FeatureServer/0/query?where=NeuGenesen IN(1,0)&objectIds=&time=&resultType=standard&outFields=AnzahlGenesen,MeldeDatum,IdBundeland&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnDistinctValues=false&cacheHint=false&orderByFields=IdBundesland&groupByFieldsForStatistics=IdBundesland&outStatistics=[{\"statisticType\":\"sum\",\"onStatisticField\":\"AnzahlGenesen\",\"outStatisticFieldName\":\"recovered\"},{\"statisticType\":\"max\",\"onStatisticField\":\"MeldeDatum\",\"outStatisticFieldName\":\"date\"}]&having=&resultOffset=&resultRecordCount=&sqlFormat=none&f=json&token="}}

The response should be checked for an error object and not only for a truthy value.

Also an option to switch off the hospitalization rates would be desirable.

marcusraitner commented 3 years ago

Thanks for debugging 😉

As for the incident at hand, see https://github.com/marlon360/rki-covid-api/issues/321

As for the error handling: Yes, I'm aware that this is quick and dirty … and I'm not particularly proud of it 😉

As for the switch for the hospitalization: This is definitely feasible and on my list.

marcusraitner commented 3 years ago

Turning of hospitalization is now possible in the latest version on master with param hosp=n … at least a workaround until the API is fixed.

marcusraitner commented 3 years ago

The API works now fine again.

marcusraitner commented 3 years ago

See also https://github.com/marlon360/rki-covid-api/issues/319

SpeedmaxX commented 2 years ago

Hello,

this error occurres again, I am getting: 2022-01-09 08:41:48: Getting hospitalization data: https://api.corona-zahlen.org/states 2022-01-09 08:41:48: {"error":{"message":"An error occurred while fetching external data.","details":"connect ETIMEDOUT 185.199.108.133:443","url":"https://raw.githubusercontent.com/robert-koch-institut/COVID-19-Hospitalisierungen_in_Deutschland/master/.zenodo.json","stack":"Error: connect ETIMEDOUT 185.199.108.133:443\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)\n at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)"}} 2022-01-09 08:41:48: Error on line 987:63: TypeError: undefined is not an object (evaluating 'hospitalizationData.data[bundesLand]')

I use 1.11.0

BG Markus P.S. Great Script!

marcusraitner commented 2 years ago

Same here. Use hosp=n as parameter as a workaround until the API is fixed (probably the RKI once again changed their Excel 🧐)

SpeedmaxX commented 2 years ago

Ok. In the meantime I did this ` if (debug) { console.log("hospi"); console.log(hospitalizationData.error); console.log(hospitalizationData); // console.log(bundesland); }

  if (!hospitalizationData || hospitalizationData.error) {
    list.addText('Keine Hospitalisierungsdaten.');
    return list;
  } `

I also got „bundesland is undefined“ then

SpeedmaxX commented 2 years ago

but location-call-result seems good

`

2022-01-09 09:01:27: location 2022-01-09 09:01:27: {"GEN":"Borken","EWZ_BL":17925570,"death_rate":1.25835938427446,"cases":25271,"deaths":318,"cases7_bl_per_100k":351.006969373917,"EWZ":371898,"BL":"Nordrhein-Westfalen","county":"LK Borken","cases7_per_100k":362.196086023587,"AGS":"05554"}

`

marcusraitner commented 2 years ago

Yes. Everything else is working. Your suggestion for improving error handling is good. As for the variable holding the "Bundesland" it is bundesLand with a capital L (do not ask me why …)

SpeedmaxX commented 2 years ago

Thanks, editing on the phone is sometimes hard…

marcusraitner commented 2 years ago

Sure. However, bundesLand is quite unconventional with the capital L … should correct this.