Skip to content

Commit

Permalink
Merge pull request #80 from NielsOerbaek/main
Browse files Browse the repository at this point in the history
Handle dependency error
  • Loading branch information
vladkens authored Oct 9, 2023
2 parents 20339b3 + dcfbfad commit e0e7fb7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions twscrape/queue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class RateLimitError(Exception):
class BannedError(Exception):
pass

class DependencyError(Exception):
pass


def req_id(rep: httpx.Response):
lr = str(rep.headers.get("x-rate-limit-remaining", -1))
Expand Down Expand Up @@ -155,6 +158,9 @@ async def _check_rep(self, rep: httpx.Response):
await self._close_ctx(-1, banned=True, msg=msg)
raise BannedError(msg)

if msg.startswith("(131) Dependency: Internal error."):
raise DependencyError(msg)

# possible banned by old api flow
if rep.status_code in (401, 403):
await self._close_ctx(utc_ts() + 60 * 60 * 12) # lock for 12 hours
Expand Down Expand Up @@ -190,6 +196,9 @@ async def req(self, method: str, url: str, params: ReqParams = None):
except (RateLimitError, BannedError):
# already handled
continue
except (DependencyError):
logger.error(f"Dependency error, returnning: {url}")
return
except (httpx.ReadTimeout, httpx.ProxyError):
# http transport failed, just retry
continue
Expand Down

0 comments on commit e0e7fb7

Please sign in to comment.