From 03ca3afbc231f668a83ca17db684e19e5a236715 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 30 Jul 2020 23:04:21 -0700 Subject: [PATCH] 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 --- zerver/lib/markdown/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index 4d38bfe3d8..ac9b1f74bd 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -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