-
Notifications
You must be signed in to change notification settings - Fork 852
Description
Description
When using users_lookupByEmail() with an email that doesn't exist on the Slack instance, I would expect the error to be returned in the response from the function. However, instead, slackclient seems to throw an exception (see details below)
Would it be possible to return the error json response from Slack API instead of throwing an exception. I'd rather handle the error response myself than putting a try except block around every Slack call :)
I could be wrong, but I seem to remember that slackclient < 2.0 used to return the error response, instead of throwing an exception
Let me know if you have any questions!
What type of issue is this? (place an x in one of the [ ])
- bug
- enhancement (feature request)
- question
- documentation related
- testing related
- discussion
Requirements (place an x in each of the [ ])
- I've read and understood the Contributing guidelines and have done my best effort to follow them.
- I've read and agree to the Code of Conduct.
- I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
slackclient version: 2.5.0
python version: 3.7
OS version(s): alpine (python:3.7-alpine)
Steps to reproduce:
- Send a
users_lookupByEmail()request with an email that doesn't correspond to a Slack user - Notice how an exception is thrown instead of the error response being returned
Expected result:
The error response gets returned from that function call
{'ok': False, 'error': 'users_not_found'}
Actual result:
An exception was thrown from within the slackclient library:
Traceback (most recent call last):
...
File "/opt/service/src/common/slack.py", line 127, in get_user_id_from_email
response = self.slack.users_lookupByEmail(email=email)
File "/usr/local/lib/python3.7/site-packages/slack/web/client.py", line 1627, in users_lookupByEmail
return self.api_call("users.lookupByEmail", http_verb="GET", params=kwargs)
File "/usr/local/lib/python3.7/site-packages/slack/web/base_client.py", line 171, in api_call
return self._event_loop.run_until_complete(future)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
return future.result()
File "/usr/local/lib/python3.7/site-packages/slack/web/base_client.py", line 226, in _send
return SlackResponse(**{**data, **res}).validate()
File "/usr/local/lib/python3.7/site-packages/slack/web/slack_response.py", line 176, in validate
raise e.SlackApiError(message=msg, response=self)
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'users_not_found'}
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.