From b443557e79258ab99239cc4b910bac176a0d9b60 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sun, 4 Apr 2021 09:22:50 -0500 Subject: [PATCH] Add TwitterServerError --- tweepy/__init__.py | 2 +- tweepy/api.py | 4 +++- tweepy/errors.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) 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""" -- 2.25.1