From 3da5edeffcab5796949c0c346b0bc187f69a6874 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sun, 4 Apr 2021 09:16:02 -0500 Subject: [PATCH] Add BadRequest --- tweepy/__init__.py | 4 ++-- tweepy/api.py | 6 ++++-- tweepy/errors.py | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tweepy/__init__.py b/tweepy/__init__.py index f08249f..19bc84b 100644 --- a/tweepy/__init__.py +++ b/tweepy/__init__.py @@ -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, diff --git a/tweepy/api.py b/tweepy/api.py index 7557991..f5f8b98 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -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: diff --git a/tweepy/errors.py b/tweepy/errors.py index e241796..5ae2bb2 100644 --- a/tweepy/errors.py +++ b/tweepy/errors.py @@ -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 -- 2.25.1