77from typing import Tuple
88import requests
99
10- from .errors import AuthorizationError , TINDError
10+ from .errors import AuthorizationError , TINDError , TooManyRequestsError
1111
1212
1313TIMEOUT : int = 30
@@ -39,6 +39,8 @@ def tind_get(
3939 :param dict|None params: Extra query parameters to send.
4040 For example, ``{'of': 'xm'}``.
4141 :raises AuthorizationError: If an invalid TIND API key is provided.
42+ :raises TooManyRequestsError: If the TIND server is overloaded with requests.
43+ :raises TINDError: If an internal server error occurs during request processing.
4244 :returns: A tuple of the HTTP status code and response text (if any).
4345 :rtype: Tuple[int, str]
4446 """
@@ -54,6 +56,8 @@ def tind_get(
5456 )
5557 if resp .status_code == 401 :
5658 raise AuthorizationError ("Invalid TIND API key provided" )
59+ if resp .status_code == 429 :
60+ raise TooManyRequestsError ("Enhance your calm" )
5761 if resp .status_code >= 500 :
5862 raise TINDError .from_json (resp .status_code , resp .text )
5963 return resp .status_code , resp .text
@@ -66,13 +70,17 @@ def tind_download(url: str, output_dir: str, api_key: str) -> Tuple[int, str]:
6670 :param str output_dir: The path to the directory in which to save the file.
6771 :param str api_key: The TIND API token.
6872 :raises AuthorizationError: If an invalid TIND API key is provided.
73+ :raises TooManyRequestsError: If the TIND server is overloaded with requests.
74+ :raises TINDError: If an internal server error occurs during request processing.
6975 :returns: A tuple of the HTTP status code and the path to the downloaded file (if successful).
7076 :rtype: Tuple[int, str]
7177 """
7278 resp = requests .get (url , headers = _auth_header (api_key ), timeout = TIMEOUT )
7379 status = resp .status_code
7480 if status == 401 :
7581 raise AuthorizationError ("Invalid TIND API key provided" )
82+ if status == 429 :
83+ raise TooManyRequestsError ("Enhance your calm" )
7684 if status >= 500 :
7785 raise TINDError .from_json (status , resp .text )
7886 if status != 200 :
0 commit comments