implement a function to run if code status is 429
hubroot opened this issue · 3 comments
There should be a function something like :
def handler:
return cache()
error, data = p3cw.request(
entity='deals',
action='',
payload={
'account_id': 59
},
_429_callback=handler
)
@hubroot from what I see from their documentation the 429 code is when you hit the rate limiter.. ergo (HTTP 429 return code is used when breaking a request rate limit.)
Why would you want to retry if you hit that? Just implement your code in a way you don't hit the limiter.
@bogdanteodoru yeah, i mean some internal check of the error code, if it's 429, the user can set their python code to get data from some cache.
Imagine you request the API accounts endpoint every 5 minutes, it's better to save at least the latest successful response in some kind of database or cache to keep the app working.
accounts = api.get('accounts', on_429_error= function(){ database.get('last saved account')}
@hubroot you could easily store that on a local variable as well if you want to keep track of a previous state. I mean, it would be an extra step from your end, of course but I would rather inform you that you hit the limit. The caching itself can be done by a local fallback function or variable that actually doing it on the library.
I wouldn't implement this at the current point as I see it more flexible to use other caching libraries or just a state variable outside the library but if this will become a pain in the ass or requested by multiple people, I will reconsider.
I will close this for now. Thanks for your input.