Skip to content

Commit 1baead6

Browse files
authored
Document exception case in README
Official documentation makes no mention of Exceptions being thrown or available. Document this behavior in the README. For example, for SMS: https://www.twilio.com/docs/sms/send-messages https://www.twilio.com/docs/sms/api/message These documentation links might lead one to think that errors that occur during the process would be stored in the message object created by the client.messages.create() call (in message.error_code, message.error_message, or message.status).
1 parent 47b66ad commit 1baead6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,27 @@ To control phone calls, your application needs to output
154154
155155
<?xml version="1.0" encoding="utf-8"?>
156156
<Response><Say>Welcome to twilio!</Say></Response>
157+
158+
Handle REST Api Exceptions
159+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
160+
161+
Decide how your application deals with problems that may arise during
162+
your API calls by watching for exceptions.
163+
164+
.. code:: python
165+
166+
from twilio.rest import Client
167+
from twilio.base.exceptions import TwilioRestException
168+
169+
account = "ACXXXXXXXXXXXXXXXXX"
170+
token = "YYYYYYYYYYYYYYYYYY"
171+
client = Client(account, token)
172+
173+
recipient = "+12316851234"
174+
message = "Hello there!"
175+
try:
176+
message = client.messages.create(to=recipient, from_="+15555555555",
177+
body=message)
178+
except TwilioRestException as e:
179+
# For example, pass the exception off to an error handling method of your creation
180+
handle_twilio_exception(e, recipient, message)

0 commit comments

Comments
 (0)