Skip to content
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

How do I get the actual response when an error raised? #1422

Closed
davies-w opened this issue Nov 8, 2023 · 1 comment
Closed

How do I get the actual response when an error raised? #1422

davies-w opened this issue Nov 8, 2023 · 1 comment
Labels
question M-T: User needs support to use the project

Comments

@davies-w
Copy link

davies-w commented Nov 8, 2023

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'}
@davies-w
Copy link
Author

davies-w commented Nov 8, 2023

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

@davies-w davies-w closed this as completed Nov 8, 2023
@WilliamBergamin WilliamBergamin added question M-T: User needs support to use the project and removed untriaged labels Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants