From: Harmon Date: Sun, 4 Apr 2021 14:22:50 +0000 (-0500) Subject: Add TwitterServerError X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b443557e79258ab99239cc4b910bac176a0d9b60;p=tweepy.git Add TwitterServerError --- diff --git a/tweepy/__init__.py b/tweepy/__init__.py index 19bc84b..3082f76 100644 --- a/tweepy/__init__.py +++ b/tweepy/__init__.py @@ -15,7 +15,7 @@ from tweepy.cache import Cache, FileCache, MemoryCache from tweepy.cursor import Cursor from tweepy.errors import ( BadRequest, Forbidden, HTTPException, NotFound, TooManyRequests, - TweepyException, Unauthorized + TweepyException, TwitterServerError, Unauthorized ) from tweepy.models import ( DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults, diff --git a/tweepy/api.py b/tweepy/api.py index f5f8b98..4855c94 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -14,7 +14,7 @@ import requests from tweepy.errors import ( BadRequest, Forbidden, HTTPException, NotFound, TooManyRequests, - TweepyException, Unauthorized + TweepyException, TwitterServerError, Unauthorized ) from tweepy.models import Model from tweepy.parsers import ModelParser, Parser @@ -221,6 +221,8 @@ class API: raise NotFound(resp) if resp.status_code == 429: raise TooManyRequests(resp) + if resp.status_code >= 500: + raise TwitterServerError(resp) if resp.status_code and not 200 <= resp.status_code < 300: raise HTTPException(resp) diff --git a/tweepy/errors.py b/tweepy/errors.py index 5ae2bb2..1ddaff6 100644 --- a/tweepy/errors.py +++ b/tweepy/errors.py @@ -66,3 +66,7 @@ class NotFound(HTTPException): class TooManyRequests(HTTPException): """Exception raised for a 429 HTTP status code""" pass + + +class TwitterServerError(HTTPException): + """Exception raised for a 5xx HTTP status code"""