Forráskód Böngészése

#IQRV #comment [Module][Restful] 调整返回值的使用

gifur 3 éve
szülő
commit
47a35e479f

+ 2 - 1
Module/include/CommEntityRestful.hpp

@@ -20,9 +20,10 @@ struct CommResponseJson : public MicroServices::API::CommResponse
     JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("success", "code", "return_code", "error_msg", "message")
 };
 
+//{ "code":"10000", "data" : true, "message" : "ÇëÇó³É¹¦", "request" : "https://rvcgray.paasst.cmbchina.cn/api/gray/way?null", "success" : true }
 struct GrayResponseJson : public MicroServices::API::GrayResponseJson
 {
-    JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, returnCode, message, graySwitch)
+    JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, errorCode, message, graySwitch)
     JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("success", "code", "message", "data")
 };
 

+ 23 - 2
Module/include/microservices/api_comm.h

@@ -45,7 +45,28 @@ struct CommResponse
 
     virtual std::string WhatError() const
     {
-        return (std::string("[") + returnCode + "] " + errorMsg);
+        std::string result("");
+
+        if (!returnCode.empty()) {
+            result += "[";
+            result += returnCode;
+            result += "]";
+        }
+        if (!errorCode.empty()) {
+            result += "[";
+            result += errorCode;
+            result += "]";
+        }
+        if (!message.empty()) {
+            result += " ";
+            result += message;
+        }
+        if (!errorMsg.empty()) {
+            result += " ";
+            result += errorMsg;
+        }
+
+        return result;
     }
 };
 
@@ -55,7 +76,7 @@ struct GrayResponseJson : public CommResponse
 
     virtual bool IsOperatedOK() const
     {
-        return (returnCode == "10000");
+        return (errorCode == "10000");
     }
 };