8000 Add exception handling to rest examples · isbo/twilio-python@111d2e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 111d2e5

Browse files
author
Adam Ballai
committed
Add exception handling to rest examples
1 parent cba65c8 commit 111d2e5

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

examples/example-rest.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,52 @@
2323
'Called' : '415-555-1212',
2424
'Url' : 'http://demo.twilio.com/welcome',
2525
}
26-
print account.request('/%s/Accounts/%s/Calls' % \
27-
(API_VERSION, ACCOUNT_SID), 'POST', d)
26+
try:
27+
print account.request('/%s/Accounts/%s/Calls' % \
28+
(API_VERSION, ACCOUNT_SID), 'POST', d)
29+
except Exception, e:
30+
print e
31+
print e.read()
2832

2933
# ===========================================================================
3034
# 2. Get a list of recent completed calls (i.e. Status = 2)
3135
# uses a HTTP GET
3236
d = { 'Status':2, }
33-
print account.request('/%s/Accounts/%s/Calls' % \
34-
(API_VERSION, ACCOUNT_SID), 'GET', d)
37+
try:
38+
print account.request('/%s/Accounts/%s/Calls' % \
39+
(API_VERSION, ACCOUNT_SID), 'GET', d)
40+
except Exception, e:
41+
print e
42+
print e.read()
3543

3644
# ===========================================================================
3745
# 3. Get a list of recent notification log entries
3846
# uses a HTTP GET
39-
print account.request('/%s/Accounts/%s/Notifications' % \
40-
(API_VERSION, ACCOUNT_SID), 'GET')
47+
try:
48+
print account.request('/%s/Accounts/%s/Notifications' % \
49+
(API_VERSION, ACCOUNT_SID), 'GET')
50+
except Exception, e:
51+
print e
52+
print e.read()
4153

4254
# ===========================================================================
4355
# 4. Get a list of audio recordings for a certain call
4456
# uses a HTTP GET
4557
d = { 'CallSid':'CA0c7001f3f3f5063b7f7d96def0f1ed00', }
46-
print account.request('/%s/Accounts/%s/Recordings' % \
47-
(API_VERSION, ACCOUNT_SID), 'GET', d)
48-
58+
try:
59+
print account.request('/%s/Accounts/%s/Recordings' % \
60+
(API_VERSION, ACCOUNT_SID), 'GET', d)
61+
except Exception, e:
62+
print e
63+
print e.read()
64+
4965
# ===========================================================================
5066
# 5. Delete a specific recording
5167
# uses a HTTP DELETE, no response is returned when using DELETE
52-
account.request( \
53-
'/%s/Accounts/%s/Recordings/RE4e75a0b62a5c52e5cb96dc25fb4101d9' % \
54-
(API_VERSION, ACCOUNT_SID), 'DELETE')
68+
try:
69+
account.request( \
70+
'/%s/Accounts/%s/Recordings/RE4e75a0b62a5c52e5cb96dc25fb4101d9' % \
71+
(API_VERSION, ACCOUNT_SID), 'DELETE')
72+
except Exception, e:
73+
print e
74+
print e.read()

0 commit comments

Comments
 (0)
0