Skip to content

Commit

Permalink
Merge pull request #55 from nonebot/fix-issue-53-new
Browse files Browse the repository at this point in the history
修复 ActionFailed 不兼容问题
  • Loading branch information
stdrc authored Jul 20, 2021
2 parents 2680ad1 + c57b989 commit f727aed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion aiocqhttp/api_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
17 changes: 11 additions & 6 deletions aiocqhttp/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<ActionFailed " + ", ".join(
f"{k}={v}" for k, v in self.info.items()) + ">"
f"{k}={repr(v)}" for k, v in self.result.items()) + ">"

def __str__(self):
return self.__repr__()
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f727aed

Please sign in to comment.