-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a custom throttling error class type. #472
Conversation
… a REST call returns a 429 status code
Thx for your help. |
There is no json result when the HMIP rest call returns a 429 status code. Because there is no content field returned by the requests lib, the code in
|
I argue that getting a 429 (or any 4XX) response code from the rest call is an exceptional state, so it would make sense to throw an exception when this happens. There is no meaningful response any of the client functions like for example |
Yes this change only affects the synchronous rest call. I have not yet experiments with web sockets implementation. I also think it would make sense to move all the custom exception classes to someplace more top level in the package, like
for example. This would be more in line with most other python packages. But I didn't want to change too much for an initial PR. |
I just added the exception to the asynchronous web sockets implementation as well. |
One more point I would make as well, why throttling errors should be reflected differently than other error response codes (by having their own exception class): I think that handling any other 4XX error 403 indicates a fundamental problem with the user code or configuration and is unlikely to succeed if retried. A throttling error is likely to succeed if repeated, assuming user code waits long enough. |
Thats exactly what i was thinking about. On which errors it is neccessary to repeat a request (with a increasing sleep time). At the end it is timeout and maybe the throttling error. All others are more fundamental problems as you said. |
Are you still interrested in refactoring the event handling? |
I believe throttling errors are bound to affect anyone who uses the library. This change introduces a custom throttling error type that is thrown whenever one of the REST calls returns a 429 status code.
Currently the code simply crashes at unrelated location and is likely confusing for any users. By throwing a custom error type, client code can more easily react to the throttling error, by avoiding any retries for the requested 15 mins.
I should note that is only a small step in the direction of proper error handling, as the
_restcall
method returns an empty string if any errors are encountered with the exception of timeout error.