33#
44# License under The MIT License (MIT). See LICENSE in project root.
55#
6+ import time
7+
68from ns1 .rest .zones import Zones
79from ns1 .records import Record
810from 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