Added exception to catch rate-limiting.

This commit is contained in:
2022-09-13 14:47:48 +12:00
parent 2c6c1f6f34
commit bbd2083109
2 changed files with 23 additions and 3 deletions

View File

@@ -1,12 +1,15 @@
import requests
import logging
from requests.auth import HTTPBasicAuth
from akauntingpy import exceptions
from akauntingpy.helpers import *
__version__ = "1.0.3"
__version__ = "1.0.5"
logger = logging.getLogger(__name__)
class Client(object):
"""
Akaunting interface.
@@ -68,6 +71,9 @@ class Client(object):
"\n".join(errors))
# elif response.status_code != 200 and response.status_code != 201:
# raise exceptions.Error(response_['message'])
elif response.status_code == 429:
# We hit the maximum requests
raise exceptions.TooManyAttempts(response_['message'])
return response_
def ping(self):
@@ -162,9 +168,15 @@ class Client(object):
transferred_at=None, # Date of expense/transfer or income
payment_method="Bank Transfer", # Payment method
amount=None, # Amount received/paid
**params # Any additional parameters
**params # Any additional parameters
):
logger.info("Transfer called with parameters")
logger.info("from_account_id: %s", from_account_id)
logger.info("to_account_id: %s", to_account_id)
logger.info("transferred_at: %s", transferred_at)
logger.info("payment_method: %s", payment_method)
logger.info("amount: %s", amount)
data = self.call(endpoint="transfers",
method="POST",
from_account_id=from_account_id,

View File

@@ -31,6 +31,14 @@ class ContactNotFound(Error):
"""
Account not found
Args:
Error (_type_): _description_
"""
class TooManyAttempts(Error):
"""
Too Many attempts to API
Args:
Error (_type_): _description_
"""