Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dispatch/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Automatically register error and output types from
# commonly used libraries.
integrations = ("httpx", "requests")
integrations = ("httpx", "requests", "slack")
for name in integrations:
try:
importlib.import_module(f"dispatch.integrations.{name}")
Expand Down
27 changes: 27 additions & 0 deletions src/dispatch/integrations/slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import slack_sdk # type: ignore
import slack_sdk.errors # type: ignore
import slack_sdk.web # type: ignore

from dispatch.integrations.http import http_response_code_status
from dispatch.status import Status, register_error_type, register_output_type


def slack_error_status(error: Exception) -> Status:
# See https://github.com/slackapi/python-slack-sdk/blob/main/slack/errors.py
match error:
case slack_sdk.errors.SlackApiError():
if error.response is not None:
return slack_response_status(error.response)

return Status.TEMPORARY_ERROR


def slack_response_status(response: slack_sdk.web.SlackResponse) -> Status:
return http_response_code_status(response.status_code)


# Register types of things that a function might return.
register_output_type(slack_sdk.web.SlackResponse, slack_response_status)

# Register base exception.
register_error_type(slack_sdk.errors.SlackClientError, slack_error_status)