-
Notifications
You must be signed in to change notification settings - Fork 291
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
Improve Slack error handling #3000
Conversation
a7c9142
to
8723e17
Compare
# Conflicts: # CHANGELOG.md
except SlackAPIException as e: | ||
if e.response["error"] == "message_not_found": # message deleted from channel | ||
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due message_not_found") | ||
elif e.response["error"] == "is_inactive": # deleted channel error | ||
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due to is_inactive") | ||
elif e.response["error"] == "account_inactive": | ||
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due to account_inactive") | ||
elif e.response["error"] == "channel_not_found": | ||
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due to channel_not_found") | ||
else: | ||
raise e | ||
logger.info(f"Finished _update_slack_message for alert_group {alert_group.pk}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing logging here as errors are already logged in SlackClient.api_call
def __init__(self, msg: str, response: SlackResponse): | ||
super().__init__(msg) | ||
self.response = response | ||
class SlackServerErrorRetryHandler(RetryHandler): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ One of the main changes in the PR
response = super(SlackClientWithErrorHandling, self).api_call(*args, **kwargs) | ||
except SlackApiError as err: | ||
response = err.response | ||
def api_call(self, *args, **kwargs) -> SlackResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ One of the main changes in the PR
body: str | ||
|
||
|
||
class SlackAPIError(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ One of the main changes in the PR
# Trying same request with access token. It is required due to migration to granular permissions | ||
# and can be removed after clients reinstall their bots |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed after clients reinstall their bots
The switch to granular permissions happened a long time ago so I think it's safe to remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, a couple of minor questions.
286d393
to
5b1be85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome cleanup/deduplication of the error handling logic 🔥
What this PR does
SlackClientWithErrorHandling
to justSlackClient
5xx
errors)Which issue(s) this PR fixes
Checklist
pr:no public docs
PR label added if not required)CHANGELOG.md
updated (orpr:no changelog
PR label added if not required)