Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Slack: fail gracefully if slack exception #2798

Merged
merged 2 commits into from
Feb 23, 2022
Merged
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
11 changes: 9 additions & 2 deletions openpype/modules/slack/plugins/publish/integrate_slack_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def process(self, instance):
message,
publish_files)

if not msg_id:
return

msg = {
"type": "slack",
"msg_id": msg_id,
Expand Down Expand Up @@ -118,7 +121,7 @@ def _get_filled_message(self, message_templ, instance, review_path=None):
def _get_thumbnail_path(self, instance):
"""Returns abs url for thumbnail if present in instance repres"""
published_path = None
for repre in instance.data['representations']:
for repre in instance.data.get("representations", []):
if repre.get('thumbnail') or "thumbnail" in repre.get('tags', []):
if os.path.exists(repre["published_path"]):
published_path = repre["published_path"]
Expand All @@ -128,7 +131,7 @@ def _get_thumbnail_path(self, instance):
def _get_review_path(self, instance):
"""Returns abs url for review if present in instance repres"""
published_path = None
for repre in instance.data['representations']:
for repre in instance.data.get("representations", []):
tags = repre.get('tags', [])
if (repre.get("review")
or "review" in tags
Expand Down Expand Up @@ -177,6 +180,8 @@ def _python2_call(self, token, channel, message, publish_files):
error_str = self._enrich_error(str(e), channel)
self.log.warning("Error happened: {}".format(error_str))

return None, []

def _python3_call(self, token, channel, message, publish_files):
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
Expand Down Expand Up @@ -206,6 +211,8 @@ def _python3_call(self, token, channel, message, publish_files):
error_str = self._enrich_error(str(e.response["error"]), channel)
self.log.warning("Error happened {}".format(error_str))

return None, []

def _enrich_error(self, error_str, channel):
"""Enhance known errors with more helpful notations."""
if 'not_in_channel' in error_str:
Expand Down