测试代码

//在POV.cc中
//4发送查询用户结果
ErrorMessage POV::handleUserSendQuery(rapidjson::Document& doc)
{
    ErrorMessage msg;
    msg.type="UserSend";
    if(!doc.HasMember("name"))
    {
        msg.errcode=343;
        msg.msg="json中不包含name字段";
        std::cout << "msg.errcode:" << msg.errcode << "\nmsg.msg:" << msg.msg << "\n";
        return msg;
    }
    std::string name=doc["name"].GetString();

    if(!blockchain.hasData("name",name,"user"))
    {
        msg.errcode=241;
        msg.msg="数据库中不存在该用户,查询失败";
  std::cout << "msg.errcode:" << msg.errcode << "\nmsg.msg:" << msg.msg << "\n";
        return msg;
    }
    else
    {
        rapidjson::Document& old_data=blockchain.getDataFromDatabase("name",name,"user",true);
        std::cout << "\n找到的用户信息为:";
        old_data[0].RemoveMember("type");
        print_document(old_data[0]);
        msg.errcode=141;
        msg.msg=getDocumentString(old_data[0]);
        msg.is_json=true;
        delete &old_data;
        std::cout << "\nmsg.errcode:" << msg.errcode << "\nmsg.msg:" << msg.msg << "\n";
        return msg;
    }
}
上一篇:.Net Core WebApi 模型验证无效时报400


下一篇:SpringBoot优雅的全局异常处理