8000 Merge pull request #100 from BlockMaster/feature-twilio-error-in-exce… · Stackdriver/twilio-python@ee4a3d2 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Commit ee4a3d2

Browse files
author
Kevin Burke
committed
Merge pull request twilio#100 from BlockMaster/feature-twilio-error-in-exception
Pass the Twilio error code with TwilioRestException
2 parents 6e59c4b + 8125136 commit ee4a3d2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

twilio/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ class TwilioException(Exception):
88

99
class TwilioRestException(TwilioException):
1010

11-
def __init__(self, status, uri, msg=""):
11+
def __init__(self, status, uri, msg="", code=None):
1212
self.uri = uri
1313
self.status = status
1414
self.msg = msg
15+
self.code = code
1516

1617
def __str__(self):
1718
return "HTTP ERROR %s: %s \n %s" % (self.status, self.msg, self.uri)

twilio/rest/resources/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ def make_twilio_request(method, uri, **kwargs):
7878
if not resp.ok:
7979
try:
8080
error = json.loads(resp.content)
81-
message = "%s: %s" % (error["code"], error["message"])
81+
code = error["code"]
82+
message = "%s: %s" % (code, error["message"])
8283
except:
84+
code = None
8385
message = resp.content
8486

85-
raise TwilioRestException(resp.status_code, resp.url, message)
87+
raise TwilioRestException(resp.status_code, resp.url, message, code)
8688

8789
return resp
8890

0 commit comments

Comments
 (0)
0