Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit c22db3e

Browse files
committed
cleanup of error handling for adding api calls
1 parent 0db4961 commit c22db3e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -857,17 +857,21 @@ def add(self, t, p1, p2=None, p3=None, p4=None, p5=None):
857857
else:
858858
branch = getattr(branch, element)
859859
except:
860-
# should never happen
861-
raise CloudFlareAPIError(0, 'api load name failed')
862-
name = a[-1]
860+
# missing path - should never happen unless api_v4 is a busted file
861+
branch = None
862+
break
863863

864+
if not branch:
865+
raise CloudFlareAPIError(0, 'api load: element **%s** missing when adding path /%s' % (element, '/'.join(a)))
866+
867+
name = a[-1]
864868
try:
865869
if '-' in name:
866870
f = getattr(branch, name.replace('-','_'))
867871
else:
868872
f = getattr(branch, name)
869-
# already exists - don't let it overwrite
870-
raise CloudFlareAPIError(0, 'api duplicate name found: %s/**%s**' % ('/'.join(a[0:-1]), name))
873+
# already exists - don't let it overwrite - should never happen unless api_v4 is a busted file
874+
raise CloudFlareAPIError(0, 'api load: duplicate name found: %s/**%s**' % ('/'.join(a[0:-1]), name))
871875
except AttributeError:
872876
# this is the required behavior - i.e. it's a new node to create
873877
pass
@@ -968,9 +972,12 @@ def __init__(self, email=None, token=None, certtoken=None, debug=False, raw=Fals
968972
self._base = self._v4base(config)
969973

970974
# add the API calls
971-
api_v4(self)
972-
if 'extras' in config and config['extras']:
973-
api_extras(self, config['extras'])
975+
try:
976+
api_v4(self)
977+
if 'extras' in config and config['extras']:
978+
api_extras(self, config['extras'])
979+
except Exception as e:
980+
raise CloudFlareAPIError(0, str(e))
974981

975982
def __call__(self):
976983
""" Cloudflare v4 API"""

0 commit comments

Comments
 (0)