8000 Clean up loop and don't catch RestExceptions · stomatocode/twilio-python@dafa11c · GitHub
[go: up one dir, main page]

Skip to content

Commit dafa11c

Browse files
committed
Clean up loop and don't catch RestExceptions
1 parent 0e0d0a2 commit dafa11c

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

twilio/rest/resources.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,27 +357,23 @@ def iter(self, **kwargs):
357357
"""
358358
Return all instance resources using an iterator
359359
"""
360-
next_uri = self.uri
361360
params = transform_params(kwargs)
362361

363-
while next_uri:
364-
try:
365-
resp, page = self.request("GET", next_uri, params=params)
366-
367-
if self.key not in page:
368-
raise StopIteration()
362+
while True:
363+
resp, page = self.request("GET", self.uri, params=params)
369364

370-
for ir in page[self.key]:
371-
yield self.load_instance(ir)
365+
if self.key not in page:
366+
raise StopIteration()
372367

373-
if not page.get('next_page_uri', ''):
374-
raise StopIteration()
368+
for ir in page[self.key]:
369+
yield self.load_instance(ir)
375370

376-
o = urlparse(page['next_page_uri'])
377-
params.update(parse_qs(o.query))
378-
except TwilioRestException:
371+
if not page.get('next_page_uri', ''):
379372
raise StopIteration()
380373

374+
o = urlparse(page['next_page_uri'])
375+
params.update(parse_qs(o.query))
376+
381377

382378
def load_instance(self, data):
383379
instance = self.instance(self, data[self.instance.id_key])

0 commit comments

Comments
 (0)
0