diff --git a/aiocqhttp/api_impl.py b/aiocqhttp/api_impl.py index 27a732c..97d20b7 100644 --- a/aiocqhttp/api_impl.py +++ b/aiocqhttp/api_impl.py @@ -34,7 +34,7 @@ def _handle_api_result(result: Optional[Dict[str, Any]]) -> Any: :raise ActionFailed: the 'status' field is 'failed' """ if isinstance(result, dict): - if result.get('status') == 'failed': + if result['status'] == 'failed': raise ActionFailed(result=result) return result.get('data') diff --git a/aiocqhttp/exceptions.py b/aiocqhttp/exceptions.py index 30cc7e7..95f7433 100644 --- a/aiocqhttp/exceptions.py +++ b/aiocqhttp/exceptions.py @@ -48,19 +48,24 @@ class ActionFailed(ApiError): ```py except ActionFailed as e: - if e.retcode > 0: - pass # error code returned by CQHTTP - elif e.retcode < 0: - pass # error code returned by CoolQ + print(e) + # 或检查返回码 + if e.retcode == 12345: + pass ``` """ def __init__(self, result: dict): - self.info = result + self.result = result + + @property + def retcode(self) -> int: + """OneBot API 请求的返回码。""" + return self.result['retcode'] def __repr__(self): return "" + f"{k}={repr(v)}" for k, v in self.result.items()) + ">" def __str__(self): return self.__repr__() diff --git a/docs/changelog.md b/docs/changelog.md index 0794767..431aee5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # 更新日志 +## v1.4.1 + +- 修复上一版本中 `ActionFailed` 的不兼容更新 [#53](https://github.com/nonebot/aiocqhttp/issues/53) + ## v1.4.0 - 调整 `ActionFailed` 错误信息格式 [#44](https://github.com/nonebot/aiocqhttp/pull/44) diff --git a/setup.py b/setup.py index eccd3f4..abf40f2 100644 --- a/setup.py +++ b/setup.py @@ -5,11 +5,12 @@ setup( name='aiocqhttp', - version='1.4.0', - url='https://github.com/cqmoe/python-aiocqhttp', + version='1.4.1', + url='https://github.com/nonebot/aiocqhttp', license='MIT License', author='Richard Chien', author_email='richardchienthebest@gmail.com', + maintainer='NoneBot Team', description='A Python SDK with async I/O for OneBot (CQHTTP).', long_description=long_description, long_description_content_type="text/markdown",