aboutsummaryrefslogtreecommitdiffstats
path: root/slack/error.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-29 00:19:17 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit8f3a5bdc1ec969ae069451ddf8c68ade002782bc (patch)
tree493fec3bbda8aa154a91854f443c0711960f5089 /slack/error.py
parentb8025c704e280551035f8c0ba60d581d78ee953a (diff)
downloadwee-slack-8f3a5bdc1ec969ae069451ddf8c68ade002782bc.tar.gz
Improve error printing
Diffstat (limited to 'slack/error.py')
-rw-r--r--slack/error.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/slack/error.py b/slack/error.py
index d69fbf9..1d9a975 100644
--- a/slack/error.py
+++ b/slack/error.py
@@ -17,7 +17,9 @@ class HttpError(Exception):
http_status_code: int,
error: str,
):
- super().__init__()
+ super().__init__(
+ f"{self.__class__.__name__}: url='{url}', return_code={return_code}, http_status_code={http_status_code}, error='{error}'"
+ )
self.url = url
self.options = options
self.return_code = return_code
@@ -35,8 +37,25 @@ class SlackApiError(Exception):
str, Union[str, int, bool, Sequence[str], Sequence[int], Sequence[bool]]
] = {},
):
- super().__init__()
+ super().__init__(
+ f"{self.__class__.__name__}: workspace={workspace}, method='{method}', params={params}, response={response}"
+ )
self.workspace = workspace
self.method = method
self.params = params
self.response = response
+
+
+def format_exception(e: BaseException):
+ if isinstance(e, HttpError):
+ return (
+ f"Error calling URL {e.url}: return code: {e.return_code}, "
+ f"http status code: {e.http_status_code}, error: {e.error}"
+ )
+ elif isinstance(e, SlackApiError):
+ return (
+ f"Error from Slack API method {e.method} with params {e.params} for workspace "
+ f"{e.workspace.name}: {e.response}"
+ )
+ else:
+ return f"Unknown error occurred: {e.__class__.__name__}: {e}"