Skip to content

Commit 281f0b9

Browse files
committed
refactor: handle StopIteration separately in exception chain
1 parent fafe288 commit 281f0b9

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

ibmcloudant/features/changes_follower.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,13 @@ def _request_callback(self):
181181
if self._stop.is_set():
182182
raise StopIteration
183183
self._buffer.put(results)
184+
except StopIteration as e:
185+
self.logger.debug('Iterator stopped.')
186+
self._buffer.join()
187+
self._buffer.put(e)
188+
break
184189
except Exception as e:
185-
if type(e) is not StopIteration:
186-
self.logger.debug(f'Exception getting changes {e}')
190+
self.logger.debug(f'Exception getting changes {e}')
187191
if (
188192
self._transient_suppression == _TransientErrorSuppression.NEVER
189193
or (
@@ -197,14 +201,8 @@ def _request_callback(self):
197201
self._buffer.join()
198202
self._buffer.put(e)
199203
break
200-
if (
201-
type(e) is ApiException and e.status_code in [400, 401, 403, 404]
202-
or type(e) is StopIteration
203-
):
204-
if type(e) is StopIteration:
205-
self.logger.debug('Iterator stopped.')
206-
else:
207-
self.logger.debug('Terminal error.')
204+
if type(e) is ApiException and e.status_code in [400, 401, 403, 404]:
205+
self.logger.debug('Terminal error.')
208206
self._buffer.join()
209207
self._buffer.put(e)
210208
break

0 commit comments

Comments
 (0)