Better exception handling when making an API call
Closed this issue · 3 comments
At the moment there are a few exceptions which can be thrown by requests when load_forecast() is called.
These are not handled nicely yet and don't result in any useful feedback.
I am having the same problem. Some exception catching could be added to the library to give us some feedback, that would be good. Otherwise some short documentation of the types of exceptions we need to catch (e.g. exceptions coming from forecastio and/or the underlying network libraries)
Here is what I get sometimes when I call load_forecast()
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
I would like to have a check if the provided API key is valid. It seems that right know the only way to detect an invalid API Key is to create a request and catch the ValueError.
This should be resolved from 1.3.4. I used the requests raise_for_status()
method before parsing the response. This will raise any non 200 responses as an exception and provide more feedback than the ValueError which was raised by parsing invalid json.