Improved error handling

This commit is contained in:
Timothy Miller 2021-03-17 01:15:07 -04:00
parent bdf8c75cad
commit 04d87d3aa6

View File

@ -36,12 +36,15 @@ def deleteEntries(type):
answer = cf_api( answer = cf_api(
"zones/" + option['zone_id'] + "/dns_records?per_page=100&type=" + type, "zones/" + option['zone_id'] + "/dns_records?per_page=100&type=" + type,
"GET", option) "GET", option)
for record in answer["result"]: if answer is None or answer["result"] is None:
identifier = str(record["id"]) time.sleep(5)
cf_api( return
"zones/" + option['zone_id'] + "/dns_records/" + identifier, for record in answer["result"]:
"DELETE", option) identifier = str(record["id"])
print("🗑️ Deleted stale record " + identifier) cf_api(
"zones/" + option['zone_id'] + "/dns_records/" + identifier,
"DELETE", option)
print("🗑️ Deleted stale record " + identifier)
def getIPs(): def getIPs():
a = None a = None
@ -83,6 +86,9 @@ def commitRecord(ip):
for option in config["cloudflare"]: for option in config["cloudflare"]:
subdomains = option["subdomains"] subdomains = option["subdomains"]
response = cf_api("zones/" + option['zone_id'], "GET", option) response = cf_api("zones/" + option['zone_id'], "GET", option)
if response is None or response["result"]["name"] is None:
time.sleep(5)
return
base_domain_name = response["result"]["name"] base_domain_name = response["result"]["name"]
ttl = 300 # default Cloudflare TTL ttl = 300 # default Cloudflare TTL
for subdomain in subdomains: for subdomain in subdomains: