Skip to content

Commit 1493564

Browse files
committed
优化异常处理
1 parent 1ed1cac commit 1493564

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/jmcomic/jm_client_impl.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,7 @@ def require_resp_success(cls, resp: JmApiResp, url: Optional[str] = None):
959959

960960
# 1. 检查是否 album_missing
961961
# json: {'code': 200, 'data': []}
962-
data = resp.model().data
963-
if isinstance(data, list) and len(data) == 0:
964-
ExceptionTool.raise_missing(resp, JmcomicText.parse_to_jm_id(url))
965-
962+
# 最新api已不存在这种情况,无需检查
966963
# 2. 是否是特殊的内容
967964
# 暂无
968965

src/jmcomic/jm_client_interface.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,24 @@ def decoded_data(self) -> str:
122122
def encoded_data(self) -> str:
123123
return self.json()['data']
124124

125+
def require_have_data(self):
126+
data = self.encoded_data
127+
if isinstance(data, list) and len(data) == 0 and self.json().get('errorMsg', None):
128+
ExceptionTool.raises_resp(f'data返回值异常: {self.text}', self)
129+
125130
@property
126131
def res_data(self) -> Any:
127132
self.require_success()
133+
self.require_have_data()
128134
from json import loads
129135
return loads(self.decoded_data)
130136

131137
@property
132138
def model_data(self) -> AdvancedDict:
133139
self.require_success()
140+
self.require_have_data()
134141
return AdvancedDict(self.res_data)
135142

136-
137143
# album-comment
138144
class JmAlbumCommentResp(JmJsonResp):
139145

src/jmcomic/jm_option.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .jm_client_impl import *
2+
from .jm_toolkit import JmcomicText
23

34

45
class CacheRegistry:
@@ -130,9 +131,9 @@ def parse_bd_rule(self, album, photo, rule):
130131
@classmethod
131132
def parse_f_string_rule(cls, album, photo, rule: str):
132133
properties = {}
133-
if album:
134+
if album is not None:
134135
properties.update(album.get_properties_dict())
135-
if photo:
136+
if photo is not None:
136137
properties.update(photo.get_properties_dict())
137138
return rule.format(**properties)
138139

0 commit comments

Comments
 (0)