You are right. We can check the end by counting yielded items and comparing the number to the "total":
```python
...
current_index = 0
while self._records:
    item = self._records.pop(0)
    yield item

    # Are we at the end?
    current_index += 1
    if current_index == self.total:
        raise StopIteration
    if not self._records:
        try:
            self._fetch_page()
        except Exception:
            e = sys.exc_info()[1]
            if (len(e.args) > 0 and
...
```