Closed nh2 closed 6 years ago
(Also there should be an exception for rate limiting, as that is rather important to handle in programs using this API.)
(Also there should be an exception for rate limiting, as that is rather important to handle in programs using this API.)
I added that in my branch, will send a PR.
I added that in my branch, will send a PR.
The code at https://github.com/elsyms/hetznercloud-py/blob/182caf09f7ed397adeb284662e6e0edcfe6b9dfa/hetznercloud/shared.py only catches some specific HTTP error status codes, continuing otherwise.
Calling code like https://github.com/elsyms/hetznercloud-py/blob/182caf09f7ed397adeb284662e6e0edcfe6b9dfa/hetznercloud/servers.py#L11-L16 also doesn't check if the response is actually a 200 status code, so as a result
result["server"]
crashes as error responses don't have that key.One example of that is when you get rate limited (https://docs.hetzner.cloud/#header-rate-limiting-1), in which case the status code is
429 Too Many Requests
with response body:hetznercloud-py
should not crash in such cases.Best would be to raise a generic exception containing the HTTP status code and response body, so that this is shown to the user when the Exception bubbles up.