I have this piece of function in apps script that runs on a time trigger every day. This fetches data from a SOAP API.
function getDataItems(response, endpoint, responseName, responseChildName) {
var document = XmlService.parse(response);
var root = document.getRootElement();
var soapenv = XmlService.getNamespace('
http://schemas.xmlsoap.org/soap/envelope/');
var ns1 = XmlService.getNamespace('
https://api.trafficvance.com/?v3='+endpoint);
var items = root.getChild('Body', soapenv)
.getChild(responseName, ns1)
.getChild('return')
.getChild(responseChildName)
.getChildren('item');
return items;
}
Sometimes (randomly) it fails with the following error:
"
TypeError: Cannot read property 'getChild' of null at getDataItems(Code:140:19)"
And then I manually run it for the date it failed and it runs successfully. What is the best way to catch this error and run the function again if it fails. So that the script can run independently without any human involvement.
I would really appreciate any help. Thanks