Add BadRequest
authorHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 14:16:02 +0000 (09:16 -0500)
committerHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 14:16:02 +0000 (09:16 -0500)
tweepy/__init__.py
tweepy/api.py
tweepy/errors.py

index f08249f30585f6ba84f29204a6814d8c0985b4d9..19bc84bab3b1e3e7e277d477b4b68e9f70c63df2 100644 (file)
@@ -14,8 +14,8 @@ from tweepy.auth import AppAuthHandler, OAuthHandler
 from tweepy.cache import Cache, FileCache, MemoryCache
 from tweepy.cursor import Cursor
 from tweepy.errors import (
-    Forbidden, HTTPException, NotFound, TooManyRequests, TweepyException,
-    Unauthorized
+    BadRequest, Forbidden, HTTPException, NotFound, TooManyRequests,
+    TweepyException, Unauthorized
 )
 from tweepy.models import (
     DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults,
index 7557991c580842bd052fdd1d13dfde2949550e0d..f5f8b98132031f18aee418b80ae6d0e52804b09e 100644 (file)
@@ -13,8 +13,8 @@ from urllib.parse import urlencode
 import requests
 
 from tweepy.errors import (
-    Forbidden, HTTPException, NotFound, TooManyRequests, TweepyException,
-    Unauthorized
+    BadRequest, Forbidden, HTTPException, NotFound, TooManyRequests,
+    TweepyException, Unauthorized
 )
 from tweepy.models import Model
 from tweepy.parsers import ModelParser, Parser
@@ -211,6 +211,8 @@ class API:
 
             # If an error was returned, throw an exception
             self.last_response = resp
+            if resp.status_code == 400:
+                raise BadRequest(resp)
             if resp.status_code == 401:
                 raise Unauthorized(resp)
             if resp.status_code == 403:
index e241796eb794f72a9386c19e2c8d4d68ece63c38..5ae2bb26c8fb565921f2d68d7b3e562432c7bc11 100644 (file)
@@ -43,6 +43,11 @@ class HTTPException(TweepyException):
             )
 
 
+class BadRequest(HTTPException):
+    """Exception raised for a 400 HTTP status code"""
+    pass
+
+
 class Unauthorized(HTTPException):
     """Exception raised for a 401 HTTP status code"""
     pass