How do I get the actual response when an error raised?
davies-w opened this issue · 1 comments
I just want to handle errors gracefully. I note that #662 apparently cleaned up issues that people had been having in this area, but it doesn't seem to have allowed some kind of "raise on error" vs "return response". I just want to be able to look at the response and handle it myself. The error has some text in it, when I print it, but why can't I just get it myself.
An Aside: The problem I'm finding with this Slack API in general is an under-documentation. For example, blithely saying "get an API token", when in fact there is a huge step of doing this, you need to create an app profile, beg an admin (or easier, create your own slack), etc, etc.
eg:
response = client.conversations_history(channel=channel_id)
if response['error'] :
...
vs
try:
response = client.conversations_history(channel=channel_id)
except Exception as e:
print(....)
which gives:
Exception: The request to the Slack API failed. (url: https://www.slack.com/api/conversations.history)
The server responded with: {'ok': False, 'error': 'not_in_channel'}
My bad, I found this page: https://slack.dev/python-slack-sdk/api-docs/slack_sdk/errors/index.html that lets me read the response directly from the Exception as e, as e.response