cyanray / mirai-cpp

本项目为 mirai-api-http 的 C++ 封装,方便使用 C++ 开发基于 mirai-api-http 插件。
GNU Affero General Public License v3.0
148 stars 38 forks source link

GetGroupMemberInfo未处理查找失败返回 #51

Closed zmdyy0318 closed 3 years ago

zmdyy0318 commented 3 years ago

改函数方法里,当http回复 "{\"code\":5,\"msg\":\"指定对象不存在\"}" 时,未捕获code值,直接使用json获取name 该函数代码如下 GroupMemberInfo MiraiBot::GetGroupMemberInfo(GID_t gid, QQ_t memberId) {

stringstream api_url;
api_url
    << "/memberInfo?sessionKey="
    << sessionKey_
    << "&target="
    << int64_t(gid)
    << "&memberId="
<< int64_t(memberId);
    auto res = http_client_.Get(api_url.str().data());
if (!res)
    throw std::runtime_error("网络错误");
if (res->status != 200)
    throw std::runtime_error("[mirai-api-http error]: " + res->body);
json re_json = json::parse(res->body);
GroupMemberInfo result;
result.Set(re_json);
return result;

}

zmdyy0318 commented 3 years ago

补充:有值时没有返回code

cyanray commented 3 years ago

根据mah的设计,这个时候应该返回非200状态码的…… 不得不做个特殊处理了