Skip to content

Commit c04cadf

Browse files
add error handling, update status check to COMPLETED, update copyright
1 parent ca1896b commit c04cadf

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

examples/zone-export.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2025 NSONE, Inc.
2+
# Copyright (c) 2026 NSONE, Inc.
33
#
44
# License under The MIT License (MIT). See LICENSE in project root.
55
#
@@ -31,5 +31,3 @@
3131
with open("example.com.txt", "w") as f:
3232
f.write(zone_file)
3333
print("Zone file saved to example.com.txt")
34-
35-
# Made with Bob

ns1/zones.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# License under The MIT License (MIT). See LICENSE in project root.
55
#
6+
import time
7+
68
from ns1.rest.zones import Zones
79
from ns1.records import Record
810
from ns1.rest.stats import Stats
@@ -304,10 +306,13 @@ def export(
304306
:return: zone file content as string
305307
:raises ZoneException: if export fails or times out
306308
"""
307-
import time
308-
309309
# Initiate the export
310-
self._rest.initiate_zonefile_export(self.zone)
310+
init_response = self._rest.initiate_zonefile_export(self.zone)
311+
if not init_response or init_response.get("status") == "FAILED":
312+
error_msg = init_response.get(
313+
"message", "Failed to initiate export"
314+
)
315+
raise ZoneException(f"Zone export initiation failed: {error_msg}")
311316

312317
# Poll the status until complete or failed
313318
start_time = time.time()
@@ -320,7 +325,7 @@ def export(
320325
status_response = self._rest.status_zonefile_export(self.zone)
321326
status = status_response.get("status")
322327

323-
if status == "COMPLETE":
328+
if status == "COMPLETED":
324329
break
325330
elif status == "FAILED":
326331
error_msg = status_response.get("message", "Unknown error")
@@ -329,10 +334,6 @@ def export(
329334
time.sleep(poll_interval)
330335

331336
# Download the zone file
332-
zone_file = self._rest.get_zonefile_export(
337+
return self._rest.get_zonefile_export(
333338
self.zone, callback=callback, errback=errback
334339
)
335-
336-
if callback:
337-
return callback(zone_file)
338-
return zone_file

0 commit comments

Comments
 (0)