|
2 | 2 | from asyncio import sleep |
3 | 3 | from time import time |
4 | 4 |
|
| 5 | +from aioaria2.exceptions import Aria2rpcException |
5 | 6 | from aiofiles.os import path as aiopath |
6 | 7 | from aiofiles.os import remove |
| 8 | +from aiohttp.client_exceptions import ClientError |
7 | 9 |
|
8 | 10 | from bot import LOGGER, intervals, task_dict, task_dict_lock |
9 | 11 | from bot.core.config_manager import Config |
@@ -62,7 +64,8 @@ async def _on_download_complete(api, data): |
62 | 64 | gid = data["params"][0]["gid"] |
63 | 65 | download = await api.tellStatus(gid) |
64 | 66 | options = await api.getOption(gid) |
65 | | - except Exception: |
| 67 | + except (Aria2rpcException, ClientError) as e: |
| 68 | + LOGGER.error(f"onDownloadComplete: {e}") |
66 | 69 | return |
67 | 70 | if options.get("follow-torrent", "") == "false": |
68 | 71 | return |
@@ -117,15 +120,15 @@ async def _on_bt_download_complete(api, data): |
117 | 120 | if task.listener.seed: |
118 | 121 | try: |
119 | 122 | await api.changeOption(gid, {"max-upload-limit": "0"}) |
120 | | - except Exception as e: |
| 123 | + except (Aria2rpcException, ClientError) as e: |
121 | 124 | LOGGER.error( |
122 | 125 | f"{e} You are not able to seed because you added global option seed-time=0 without adding specific seed_time for this torrent GID: {gid}", |
123 | 126 | ) |
124 | 127 | else: |
125 | 128 | try: |
126 | 129 | await api.forcePause(gid) |
127 | | - except Exception as e: |
128 | | - LOGGER.error(f"{e} GID: {gid}") |
| 130 | + except (Aria2rpcException, ClientError) as e: |
| 131 | + LOGGER.error(f"onBtDownloadComplete: {e} GID: {gid}") |
129 | 132 | await task.listener.on_download_complete() |
130 | 133 | if intervals["stopAll"]: |
131 | 134 | return |
@@ -171,13 +174,11 @@ async def _on_download_error(api, data): |
171 | 174 | await sleep(1) |
172 | 175 | LOGGER.info(f"onDownloadError: {gid}") |
173 | 176 | error = "None" |
174 | | - try: |
| 177 | + with contextlib.suppress(Aria2rpcException, ClientError): |
175 | 178 | download = await api.tellStatus(gid) |
176 | 179 | options = await api.getOption(gid) |
177 | 180 | error = download.get("errorMessage", "") |
178 | 181 | LOGGER.info(f"Download Error: {error}") |
179 | | - except Exception: |
180 | | - pass |
181 | 182 | if options.get("follow-torrent", "") == "false": |
182 | 183 | return |
183 | 184 | if task := await get_task_by_gid(gid): |
|
0 commit comments