Raise NotFound when encountering 404 status codes in BaseClient.request
authorHarmon <Harmon758@gmail.com>
Thu, 24 Mar 2022 06:18:30 +0000 (01:18 -0500)
committerHarmon <Harmon758@gmail.com>
Thu, 24 Mar 2022 06:19:13 +0000 (01:19 -0500)
Raise NotFound rather than HTTPException when encountering 404 response status codes in BaseClient.request

tweepy/client.py

index 8937fe9323939774ad8c9cb9e6fb08544e974f4c..819aee5f4b856a5242070aa7e9f02bd588ff9446 100644 (file)
@@ -21,8 +21,8 @@ import requests
 import tweepy
 from tweepy.auth import OAuth1UserHandler
 from tweepy.errors import (
-    BadRequest, Forbidden, HTTPException, TooManyRequests, TwitterServerError,
-    Unauthorized
+    BadRequest, Forbidden, HTTPException, NotFound, TooManyRequests,
+    TwitterServerError, Unauthorized
 )
 from tweepy.list import List
 from tweepy.media import Media
@@ -97,7 +97,8 @@ class BaseClient:
                 raise Unauthorized(response)
             if response.status_code == 403:
                 raise Forbidden(response)
-            # Handle 404?
+            if response.status_code == 404:
+                raise NotFound(response)
             if response.status_code == 429:
                 if self.wait_on_rate_limit:
                     reset_time = int(response.headers["x-rate-limit-reset"])