Fix: fritzbox error when response contains empty values

This commit is contained in:
Thorben Grove 2023-12-10 19:53:40 +01:00
parent bccd73fe2d
commit 7ac19dd1d7

View File

@ -33,9 +33,9 @@ async function requestEndpoint(apiBaseUrl, service, action) {
const response = {};
try {
const jsonData = JSON.parse(xml2json(data));
const responseElements = jsonData?.elements[0]?.elements[0]?.elements[0]?.elements || [];
const responseElements = jsonData?.elements?.[0]?.elements?.[0]?.elements?.[0]?.elements || [];
responseElements.forEach((element) => {
response[element.name] = element.elements[0]?.text || "";
response[element.name] = element.elements?.[0].text || "";
});
} catch (e) {
logger.debug(`Failed parsing ${service}->${action} response:`, data);