Переглянути джерело

#IQRV #comment [CenterSetting] 下载集中配置失败添加详细报错信息

gifur 3 роки тому
батько
коміт
b83a334ef5

+ 33 - 21
Module/mod_CenterSetting/CenterSettingConn.cpp

@@ -17,11 +17,13 @@ using std::regex;
 bool CenterSettingResponse::Parse(string strData)
 {
 		bSuccess = false;
+		errInfo.clear();
 
 		Json::Value root;
 		Json::Reader reader;
 		if (!reader.parse(strData, root, false)) {
-			Dbg("%d", __LINE__);
+			errInfo = "parse json string failed: ";
+			errInfo += strData;
 			return false;
 		}
 
@@ -30,8 +32,13 @@ bool CenterSettingResponse::Parse(string strData)
 			JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("success", "code", "return_code", "error_msg", "message")
         } reponseStatus;
 
-        if (!Json2Object(reponseStatus, root) || !reponseStatus.IsReqBusinessSucc()) {
-            Dbg("%d", __LINE__);
+		if (!Json2Object(reponseStatus, root)) {
+			errInfo = "Json2Object failed";
+			return false;
+		}
+
+        if (!reponseStatus.IsReqBusinessSucc()) {
+			errInfo = reponseStatus.WhatError();
             return false;
         }
 
@@ -40,7 +47,7 @@ bool CenterSettingResponse::Parse(string strData)
 			centerSyncInfo.biz.mapSiteName = "LAN";
             centerSyncInfo.dmz.mapSiteName = "DMZ";
         } else {
-            Dbg("%d", __LINE__);
+            errInfo = "parse json data node failed: ";
         }
 		return bSuccess;
 }
@@ -124,7 +131,7 @@ ErrorCodeEnum CenterSettingsMicroServiceHelper::GrayLaunch(BOOL& grayLaunch)
 }
 
 
-ErrorCodeEnum CenterSettingsMicroServiceHelper::GetCenterSetting()
+ErrorCodeEnum CenterSettingsMicroServiceHelper::GetCenterSetting(CSimpleStringA& strErrMsg)
 {
     LOG_FUNCTION();
     CenterSettingReq req;
@@ -139,25 +146,30 @@ ErrorCodeEnum CenterSettingsMicroServiceHelper::GetCenterSetting()
     bool ret = pHttpFunc->Post(req, response);
 	pHttpFunc->Destory();
 
-    if (ret && response.bSuccess) {
+	if (ret) {
+		if (response.bSuccess) {
+            if ((mTerminalInfo.strSite.Compare("cmb.LIB", true) == 0 && response.centerSyncInfo.biz.lastUpdateTime == req.m_last_update_time)
+                || (mTerminalInfo.strSite.Compare("cmb.FLB", true) == 0 && response.centerSyncInfo.dmz.lastUpdateTime == req.m_last_update_time)) {//行内
+                Dbg("Centersetting not changed.");
+                return Error_Succeed;
+            }
+
+            CenterSettingConfigJson& cur = response.centerSyncInfo.dmz;
+            if (mTerminalInfo.strSite.Compare("cmb.LIB", true) == 0) {
+                cur = response.centerSyncInfo.biz;
+            }
+            Dbg("local last update time(%s) vs server last update time(%s)", cur.lastUpdateTime.c_str(), req.m_last_update_time.c_str());
+            SyncConfigAndRenameCenterFile(cur);
+            LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_UPDATE,
+                     CSimpleString::Format("Update CenterSetting.%s.ini.", cur.mapSiteName.c_str()));
 
-		if ((mTerminalInfo.strSite.Compare("cmb.LIB", true) == 0 && response.centerSyncInfo.biz.lastUpdateTime == req.m_last_update_time)
-			|| (mTerminalInfo.strSite.Compare("cmb.FLB", true) == 0 && response.centerSyncInfo.dmz.lastUpdateTime == req.m_last_update_time)) {//行内
-            Dbg("Centersetting not changed.");
             return Error_Succeed;
+		} else {
+			strErrMsg = response.errInfo.c_str();
 		}
-
-		CenterSettingConfigJson& cur = response.centerSyncInfo.dmz;
-		if (mTerminalInfo.strSite.Compare("cmb.LIB", true) == 0) {
-			cur = response.centerSyncInfo.biz;
-		}
-        Dbg("local last update time(%s) vs server last update time(%s)", cur.lastUpdateTime.c_str(), req.m_last_update_time.c_str());
-        SyncConfigAndRenameCenterFile(cur);
-        LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_UPDATE,
-                 CSimpleString::Format("Update CenterSetting.%s.ini.", cur.mapSiteName.c_str()));
-
-        return Error_Succeed;
-    }
+	} else {
+		strErrMsg = CSimpleStringA::Format("post [%s] failed!", req.m_url.c_str());
+	}
 
     return Error_Unexpect;
 }

+ 2 - 1
Module/mod_CenterSetting/CenterSettingConn.h

@@ -112,6 +112,7 @@ struct CenterSettingResponse : CHTTPRet {
 	CenterSettingResponse(){}
 	CenterSettingFileJson centerSyncInfo;
 	bool bSuccess;
+	std::string errInfo;
 
 	virtual bool Parse(string strData);
 };
@@ -132,7 +133,7 @@ struct CenterSettingsMicroServiceHelper
 	}
 
 	ErrorCodeEnum GrayLaunch(BOOL& grayLaunch);
-	ErrorCodeEnum GetCenterSetting();
+	ErrorCodeEnum GetCenterSetting(CSimpleStringA& strErrMsg);
 
 	void SetServicesUrl(const CSimpleStringA& value) { m_strCenterSettingUrl = value; }
 

+ 8 - 4
Module/mod_CenterSetting/mod_centersetting.cpp

@@ -136,9 +136,11 @@ void CCenterSettingEntity::OnStarted()
          } else {
              microHelper.SetServicesUrl(strServiceLink);
          }
-         const ErrorCodeEnum rc = microHelper.GetCenterSetting();
+         CSimpleStringA strLastErrInfo(true);
+         const ErrorCodeEnum rc = microHelper.GetCenterSetting(strLastErrInfo);
          if (rc != Error_Succeed) {
-             LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_CONNECT_FAILED, "Get centersetting failed.");
+             LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_CONNECT_FAILED, 
+                     CSimpleStringA::Format("Get centersetting failed:%s", strLastErrInfo.GetData()));
          } else {
              if (SP::Module::Comm::Settings::IsUsingSubBranchServerConfig(this)) {
                  LogWarn(Severity_Middle, Error_Debug, ERR_MOD_CENTERSETTING_CHANGE_FROM_SUB2HEADBRANCH, "CenterSetting Source Change: from branch to head");
@@ -166,9 +168,11 @@ void CCenterSettingEntity::OnStarted()
          if (SP::Module::Comm::Settings::IsUsingHeadBranchServices(this)) {
              CenterSettingsMicroServiceHelper microHelper(this);
              if (microHelper.IsConfigureValid()) {
-                 const ErrorCodeEnum rc = microHelper.GetCenterSetting();
+                 CSimpleStringA strLastErrInfo(true);
+                 const ErrorCodeEnum rc = microHelper.GetCenterSetting(strLastErrInfo);
                  if (rc != Error_Succeed) {
-                     LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_CONNECT_FAILED, "Get centersetting failed.");
+                     LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_CONNECT_FAILED, 
+                             CSimpleStringA::Format("Get centersetting failed:%s", strLastErrInfo.GetData()));
                  } else {
                      LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_CONNECT_SUCC, "Get centersetting succ.");
                  }