55#
66
77from . import resource
8+ from .errors import ResourceException
89
910
1011class Zones (resource .BaseResource ):
@@ -227,8 +228,6 @@ def get_zonefile_export(self, zone, callback=None, errback=None):
227228 # Note: This endpoint returns raw zone file text, not JSON
228229 # The transport layer will try to parse it as JSON and fail
229230 # We catch that exception and extract the raw body text
230- from ns1 .rest .errors import ResourceException
231-
232231 try :
233232 return self ._make_request (
234233 "GET" ,
@@ -237,14 +236,15 @@ def get_zonefile_export(self, zone, callback=None, errback=None):
237236 errback = errback ,
238237 )
239238 except ResourceException as e :
240- # If it's about invalid JSON, that's expected - extract the body
241- if "invalid json in response" in str (e ):
242- # The body is the third argument in ResourceException
243- if hasattr (e , "args" ) and len (e .args ) >= 3 :
244- body = e .args [2 ]
245- if callback :
246- return callback (body )
247- return body
239+ # Check if this is a valid zonefile response (plain text)
240+ # The response should be 200 OK with text/plain content
241+ if e .response and e .response .getcode () == 200 :
242+ # Check content-type header for text/plain
243+ content_type = e .response .getheader ("Content-Type" , "" )
244+ if "text/plain" in content_type or "text" in content_type :
245+ # This is the expected plain text zonefile
246+ return e .body if e .body else ""
247+ # Otherwise, this is a real error - re-raise it
248248 raise
249249
250250
0 commit comments