Slack - enhanced logging and protection against failure (#5287)

* OP-6248 - enhanced logging and protection against failure

Covered issues found in production on customer site. SlackAPI exception doesn't need to have 'error', covered uncaught exception.

---------

Co-authored-by: Roy Nieterau <roy_nieterau@hotmail.com>
This commit is contained in:
Petr Kalis 2023-07-13 14:20:27 +02:00 committed by GitHub
parent 956432eb5d
commit 46a238c8b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -350,6 +350,10 @@ class SlackPython3Operations(AbstractSlackOperations):
self.log.warning("Cannot pull user info, "
"mentions won't work", exc_info=True)
return [], []
except Exception:
self.log.warning("Cannot pull user info, "
"mentions won't work", exc_info=True)
return [], []
return users, groups
@ -377,8 +381,12 @@ class SlackPython3Operations(AbstractSlackOperations):
return response.data["ts"], file_ids
except SlackApiError as e:
# # You will get a SlackApiError if "ok" is False
error_str = self._enrich_error(str(e.response["error"]), channel)
self.log.warning("Error happened {}".format(error_str))
if e.response.get("error"):
error_str = self._enrich_error(str(e.response["error"]), channel)
else:
error_str = self._enrich_error(str(e), channel)
self.log.warning("Error happened: {}".format(error_str),
exc_info=True)
except Exception as e:
error_str = self._enrich_error(str(e), channel)
self.log.warning("Not SlackAPI error", exc_info=True)
@ -448,12 +456,14 @@ class SlackPython2Operations(AbstractSlackOperations):
if response.get("error"):
error_str = self._enrich_error(str(response.get("error")),
channel)
self.log.warning("Error happened: {}".format(error_str))
self.log.warning("Error happened: {}".format(error_str),
exc_info=True)
else:
return response["ts"], file_ids
except Exception as e:
# You will get a SlackApiError if "ok" is False
error_str = self._enrich_error(str(e), channel)
self.log.warning("Error happened: {}".format(error_str))
self.log.warning("Error happened: {}".format(error_str),
exc_info=True)
return None, []