Skip to content

Commit

Permalink
Handle empty zones correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolai Buchwitz committed Aug 13, 2018
1 parent 273b6dc commit c131a77
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nc_dnsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def request(self, action, **kwargs):

if data['status'] == 'success':
return data
# empty dns zone
elif data['statuscode'] == 5029:
return []
else:
raise Exception("{} ({})".format(data['longmessage'], data['statuscode']))
else:
Expand Down Expand Up @@ -116,6 +119,9 @@ def update_dns_records(self, domain, records):
"dnsrecordset": {"dnsrecords": [record.__dict__ for record in records]}
})

if 'responsedata' not in data:
return []

return [DNSRecord(**r) for r in data['responsedata']['dnsrecords']]

def dns_record_exists(self, domain, record):
Expand Down Expand Up @@ -152,6 +158,10 @@ def delete_dns_records(self, domain, records):

def dns_records(self, domain):
data = self.request("infoDnsRecords", params={"domainname": domain})

if 'responsedata' not in data:
return []

return [DNSRecord(**r) for r in data['responsedata']['dnsrecords']]

def update_dns_zone(self, domain, zone):
Expand Down

0 comments on commit c131a77

Please sign in to comment.