Skip to content

Commit

Permalink
cleanup of error handling for adding api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Aug 10, 2022
1 parent 0db4961 commit c22db3e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions CloudFlare/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,17 +857,21 @@ def add(self, t, p1, p2=None, p3=None, p4=None, p5=None):
else:
branch = getattr(branch, element)
except:
# should never happen
raise CloudFlareAPIError(0, 'api load name failed')
name = a[-1]
# missing path - should never happen unless api_v4 is a busted file
branch = None
break

if not branch:
raise CloudFlareAPIError(0, 'api load: element **%s** missing when adding path /%s' % (element, '/'.join(a)))

name = a[-1]
try:
if '-' in name:
f = getattr(branch, name.replace('-','_'))
else:
f = getattr(branch, name)
# already exists - don't let it overwrite
raise CloudFlareAPIError(0, 'api duplicate name found: %s/**%s**' % ('/'.join(a[0:-1]), name))
# already exists - don't let it overwrite - should never happen unless api_v4 is a busted file
raise CloudFlareAPIError(0, 'api load: duplicate name found: %s/**%s**' % ('/'.join(a[0:-1]), name))
except AttributeError:
# this is the required behavior - i.e. it's a new node to create
pass
Expand Down Expand Up @@ -968,9 +972,12 @@ def __init__(self, email=None, token=None, certtoken=None, debug=False, raw=Fals
self._base = self._v4base(config)

# add the API calls
api_v4(self)
if 'extras' in config and config['extras']:
api_extras(self, config['extras'])
try:
api_v4(self)
if 'extras' in config and config['extras']:
api_extras(self, config['extras'])
except Exception as e:
raise CloudFlareAPIError(0, str(e))

def __call__(self):
""" Cloudflare v4 API"""
Expand Down

0 comments on commit c22db3e

Please sign in to comment.