Closed bdowling closed 6 years ago
would robust logging
do better for this kind of debugging? By creating a named logger for the library, we could add additional debug information along with the trace.
try:
res = request.get(ADDRESS, params=params)
res.raise_for_status()
except Exception:
logger.error('failed GET: %s', ADDRESS, exc_info=True)
logger.error(res.json())
raise
And if users need better info, they could use logging.getLogger('Robinhood')
to subscribe to issues.
https://docs.python.org/3.6/howto/logging.html#advanced-logging-tutorial
@bdowling I agree we need to expose the error message. I like your solution and the logging suggestion @lockefox has provided
Looks like this was fixed in PR #62.
Throughout the API we use the requests.raise_for_status, however this often hides the API usage hints that Robinhood returns in the content of the error message which makes it harder to troubleshoot. (I'm certain more than a few of us have been confounded by this at times)
I experimented with a few options. One of them being the exception chaining, but that just seemed clumsy, resulted in useless extra traceback and is also only py3 compatible.
I finally ended up with this:
Which results in error messages such as (last line being the addition):
Essentially all calls to res.raise_for_status() would be replaced with:
Always more than one way to skin it, but I figured this was a reasonable approach. Let me know your thoughts.