markdown: Treat more twitter codes as also permanent failures.

Per the API documentation[1], the following codes all correspond to
HTTP 404:

 - `34`: **Sorry, that page does not exist.**  The specified resource
   was not found.
 - `144`: **No status found with that ID.**  The requested Tweet ID is
   not found (if it existed, it was probably deleted)
 - `421`: **This Tweet is no longer available.**  The Tweet cannot be
   retrieved. This may be for a number of reasons.
 - `422`: **This Tweet is no longer available because it violated the
   Twitter Rules.**  The Tweet is not available in the API.

Treat all of these identically.

[1] https://developer.twitter.com/en/docs/basics/response-codes
This commit is contained in:
Alex Vandiver 2020-07-30 23:04:21 -07:00 committed by Tim Abbott
parent fc141af30e
commit 03ca3afbc2
1 changed files with 4 additions and 3 deletions

View File

@ -413,9 +413,10 @@ def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]:
t = e.args[0]
if len(t) == 1 and ('code' in t[0]):
code = t[0]['code']
if code == 34:
# Code 34 means that the message doesn't exist; return
# None so that we will cache the error
if code in [34, 144, 421, 422]:
# All these "correspond with HTTP 404," and mean
# that the message doesn't exist; return None so
# that we will cache the error.
return None
elif code in [88, 130]:
# Code 88 means that we were rate-limited and 130