Hi Forum,
I have a problem with a Javascript after updating from 4.2.1 to 4.3.3. “JavaScript Scripting (Nashorn)” as Automation is installed.
I use this function in a rule to read wanrings.json (not a valid JSON-Result is returned):
var String jsonString = sendHttpGetRequest("https://www.dwd.de/DWD/warnungen/warnapp/json/warnings.json", headers, 10000)
Then I call this script to transform to a valid JSON-format (works many years ago):
var String newString = transform("JS", "Wetter_DWD_getWarningsJSON.js", jsonString)
The problem is in this function:
(function(jsonString) {
var newString = jsonString.replace('warnWetter.loadWarnings(','');
newString = newString.replace(');','');
var newJSON = JSON.parse(newString);
var jsonResult = "";
if (newJSON.warnings.hasOwnProperty('109174000')) {
jsonResult =JSON.stringify(newJSON.warnings['109174000'][0]);
} else jsonResult = 'NULL'
return jsonResult;
})(input)
I get the following error-message in the openHAB-Log:
2025-03-15 08:38:09.846 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'Test-13' failed: warnWetter.loadWarnings({"time":1742023862000,"warnings":{"103401000":[{"state":"Niedersachsen","type":6,"level":2,"start":1741978800000,"regionName":"Stadt Delmenhorst","end":1742025600000,"description":"Es besteht Glättegefahr.","event":"GLÄTTE","headline":"Amtliche WARNUNG vor GLÄTTE","instruction":"Hinweis auf Rutschgefahr. \nHandlungsempfehlungen: \nVerhalten im Straßenverkehr anpassen","stateShort":"NS","altitudeStart":null,"altitudeEnd":null}, MORE TEXT REMOVED); is not in a valid format. in Test
It seems that something didn’t work in the JavaScript or the JS-script don’t execute. Before and after I call the JavaScript, I’ll get the same wrong JSON in the variables in openHAB-rule.
Someone has an idea how to debug the JavaScript or know this behavior since Update 4.3.3?
Thanks,
Reinhard
- Platform information:
- Hardware: Raspberry Pi 32 Bit
- OS: Buster
- Java Runtime Environment: zulu17.48.15-ca-hl-jdk17.0.10-linux_aarch32hf.tar.gz
- openHAB version: 4.3.3