Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] EnsureSuccess 状态码500对应的错误原因有误以及缺乏关键提示信息 #73

Closed
Natsukage opened this issue Mar 16, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Natsukage
Copy link
Contributor

发生了什么事?
目前EnsureSuccess()方法中的json.OfErrorMessage()部分在code=500时会直接返回文件上传错误。并且抛出的错误中,只包含引发错误时Mirai.Net发送的数据,而没有包括MAH端的回应。因此无法根据回应来判断错误的具体内容

举例来说,比如机器人短时间内群发太多内容触发了风控的话,会得到以下回应(其中***部分为群号)

{
  "code": 500,
  "msg": "Failed sending message to Group(**********), reason=LIMITED_MESSAGING. Tips: 问题原因可能是账号被多次举报或被服务器认为不安全. 若账号在官方客户端也无法发出消息, 可尝试用手机 QQ 登录后访问 https://accounts.qq.com/safe/message/unlock?lock_info=5_5 解冻."
}

此外,也包含以下等各种其他情况

500
Send message failed: MessageSvcPbSendMsg.Response.Failed(resultType=110, errorCode=0, errorMessage=发送失败,你已被移出该群,请重新加群。)
500
message is empty 

由于在发送消息的过程中,EnsureSuccess()抛出的异常并不包括返回的msg部分,导致无法在程序中判断错误的具体原因并进行处理。

例如一个应用场景:如果机器人发送消息时触发了上面的风控导致消息发不出去,那么就通过私聊告诉机器人的主人提醒手动上号解冻。

那么这里就需要自己在机器人中手动构筑一个自己的SendGroupMessage()方法封装MessageManager.SendGroupMessageAsync()来捕获异常,并根据异常的种类来判断是否需要发送私聊消息进行上报。

怎么复现?
如上面的例子,可以简单地直接发送空消息至群聊,或发送至已经被解散的群、已经退出的群号等,都可以得到MAH的500错误反馈。

修改建议
希望throw出包含更多内容的自定义异常类,而非直接将错误文字拼装成string并返回。
例如将code与msg封装入exception的自定义字段中,使得程序在catch异常ex后,可以通过ex.code\ex.msg\ex.payload等属性分别获取错误的各项具体内容

环境

  • Mirai版本: 2.14.0
  • Mirai版本: 2.9.1
  • 版本: 2.4.8
@Natsukage Natsukage added the bug Something isn't working label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant