Skip to content

Commit 09471dd

Browse files
committed
完善异常上抛机制
1 parent 783bf4c commit 09471dd

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

src/jmcomic/jm_downloader.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
from .jm_option import *
22

33

4+
def catch_exception(field_name):
5+
def deco(func):
6+
def wrapper(self, *args, **kwargs):
7+
try:
8+
return func(self, *args, **kwargs)
9+
except Exception as e:
10+
detail: JmBaseEntity = args[1]
11+
getattr(self, field_name).append((detail, e))
12+
if detail.is_image():
13+
detail: JmImageDetail
14+
jm_log('image.failed', f'图片下载失败: [{detail.download_url}], 异常: {e}')
15+
16+
elif detail.is_photo():
17+
detail: JmPhotoDetail
18+
jm_log('photo.failed', f'章节下载失败: [{detail.id}], 异常: {e}')
19+
20+
raise e
21+
22+
return wrapper
23+
24+
return deco
25+
26+
427
# noinspection PyMethodMayBeStatic
528
class DownloadCallback:
629

@@ -56,29 +79,6 @@ def __init__(self, option: JmOption) -> None:
5679
self.download_failed_image: List[Tuple[JmImageDetail, BaseException]] = []
5780
self.download_failed_photo: List[Tuple[JmPhotoDetail, BaseException]] = []
5881

59-
@staticmethod
60-
def catch_exception(field_name):
61-
def deco(func):
62-
def wrapper(self, *args, **kwargs):
63-
try:
64-
return func(self, *args, **kwargs)
65-
except Exception as e:
66-
detail: JmBaseEntity = args[1]
67-
getattr(self, field_name).append((detail, e))
68-
if detail.is_image():
69-
detail: JmImageDetail
70-
jm_log('image.failed', f'图片下载失败: [{detail.download_url}], 异常: {e}')
71-
72-
elif detail.is_photo():
73-
detail: JmPhotoDetail
74-
jm_log('photo.failed', f'章节下载失败: [{detail.id}], 异常: {e}')
75-
76-
raise e
77-
78-
return wrapper
79-
80-
return deco
81-
8282
def download_album(self, album_id):
8383
client = self.client_for_album(album_id)
8484
album = client.get_album_detail(album_id)

0 commit comments

Comments
 (0)