Skip to content

Commit

Permalink
Add BadRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Apr 4, 2021
1 parent 4a9bc58 commit 3da5ede
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tweepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
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,
Expand Down
6 changes: 4 additions & 2 deletions tweepy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
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
Expand Down Expand Up @@ -211,6 +211,8 @@ def request(

# 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:
Expand Down
5 changes: 5 additions & 0 deletions tweepy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def __init__(self, response):
)


class BadRequest(HTTPException):
"""Exception raised for a 400 HTTP status code"""
pass


class Unauthorized(HTTPException):
"""Exception raised for a 401 HTTP status code"""
pass
Expand Down

0 comments on commit 3da5ede

Please sign in to comment.