diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-19 20:40:32 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | d6b4f505d53e69ecb39d518a89d8d0013e22ad51 (patch) | |
tree | 2826b143dcf48d078d678255f6f7b0d715dc6c43 /slack/task.py | |
parent | 18f59853a045365b3d6bab26ca5d599b8cbc82db (diff) | |
download | wee-slack-d6b4f505d53e69ecb39d518a89d8d0013e22ad51.tar.gz |
Print error message on http/api error
Diffstat (limited to 'slack/task.py')
-rw-r--r-- | slack/task.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/slack/task.py b/slack/task.py index 9ebcad5..ac3677b 100644 --- a/slack/task.py +++ b/slack/task.py @@ -15,6 +15,8 @@ from uuid import uuid4 import weechat +from slack.error import HttpError, SlackApiError +from slack.log import print_error from slack.shared import shared from slack.util import get_callback_name @@ -74,7 +76,21 @@ def weechat_task_cb(data: str, *args: Any) -> int: def task_runner(task: Task[Any], response: Any): while True: try: - future = task.coroutine.send(response) + try: + future = task.coroutine.send(response) + except HttpError as e: + print_error( + f"Error calling URL {e.url}: return code: {e.return_code}, " + f"http status code: {e.http_status_code}, error: {e.error}" + ) + return + except SlackApiError as e: + print_error( + f"Error from Slack API method {e.method} for workspace " + f"{e.workspace.name}: {e.response}" + ) + return + if future.finished: response = future.result else: |