File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
src/dispatch/integrations Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 66
77# Automatically register error and output types from
88# commonly used libraries.
9- integrations = ("httpx" , "requests" )
9+ integrations = ("httpx" , "requests" , "slack" )
1010for name in integrations :
1111 try :
1212 importlib .import_module (f"dispatch.integrations.{ name } " )
Original file line number Diff line number Diff line change 1+ import slack_sdk # type: ignore
2+ import slack_sdk .errors # type: ignore
3+ import slack_sdk .web # type: ignore
4+
5+ from dispatch .integrations .http import http_response_code_status
6+ from dispatch .status import Status , register_error_type , register_output_type
7+
8+
9+ def slack_error_status (error : Exception ) -> Status :
10+ # See https://github.com/slackapi/python-slack-sdk/blob/main/slack/errors.py
11+ match error :
12+ case slack_sdk .errors .SlackApiError ():
13+ if error .response is not None :
14+ return slack_response_status (error .response )
15+
16+ return Status .TEMPORARY_ERROR
17+
18+
19+ def slack_response_status (response : slack_sdk .web .SlackResponse ) -> Status :
20+ return http_response_code_status (response .status_code )
21+
22+
23+ # Register types of things that a function might return.
24+ register_output_type (slack_sdk .web .SlackResponse , slack_response_status )
25+
26+ # Register base exception.
27+ register_error_type (slack_sdk .errors .SlackClientError , slack_error_status )
You can’t perform that action at this time.
0 commit comments