Skip to content

Commit

Permalink
Authorize (app_id/app_key) handles 404 and 403 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Feb 13, 2017
1 parent 05e5be5 commit 1152cbe
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ThreeScalePY.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ def authorize(self, timeout = 10):
self.auth_xml = resp
return True
except urllib2.HTTPError, err:
if err.code == 409: # a 409 means correct credentials but authorization failed
if err.code == 409 or err.code == 403 or err.code == 404:
self.authorized = False
self.error_code = err.code
self.auth_xml = err.read()
return False

Expand Down Expand Up @@ -394,13 +395,18 @@ def build_auth_response(self):
except Exception, err:
raise ThreeScaleException("Invalid xml %s" % err)

resp.set_plan(xml.xpath('/status/plan')[0].text)
status = xml.xpath('/status')
if status:
resp.set_plan(xml.xpath('/status/plan')[0].text)
reports = xml.xpath('/status/usage_reports/usage_report')
for report in reports:
resp.add_usage_report(report)

if not self.authorized:
resp.set_reason(xml.xpath('/status/reason')[0].text)
reports = xml.xpath('/status/usage_reports/usage_report')
for report in reports:
resp.add_usage_report(report)
if self.error_code == 409 and status:
resp.set_reason(xml.xpath('/status/reason')[0].text)
elif self.error_code == 403 or self.error_code == 404:
resp.set_reason(xml.xpath('/error')[0].text)
return resp


Expand Down

0 comments on commit 1152cbe

Please sign in to comment.