update: 更新自打点版本, 新增错误解析兼容逻辑
							parent
							
								
									fac01f8109
								
							
						
					
					
						commit
						603a78736e
					
				
										
											Binary file not shown.
										
									
								
							|  | @ -6,9 +6,7 @@ namespace Guru | |||
|     using System.Collections.Generic; | ||||
|     using System.Globalization; | ||||
|     using System.Linq; | ||||
|     using System.Text; | ||||
|     using Newtonsoft.Json; | ||||
|     using Newtonsoft.Json.Linq; | ||||
|     using UnityEngine; | ||||
| 
 | ||||
|      | ||||
|  | @ -334,55 +332,75 @@ namespace Guru | |||
|         /// <param name="msg"></param> | ||||
|         private static void OnSDKCallback(string msg) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(msg)) return; | ||||
| 
 | ||||
|             //------- message send to unity ---------- | ||||
|             Debug.Log($"{Tag} get callback errorInfo:\n{msg}"); | ||||
| 
 | ||||
|             string patten = ""; | ||||
|             string patten2 = ""; | ||||
|             int idx = 0; | ||||
|             int idx2 = 0; | ||||
|             int len = 0; | ||||
| 
 | ||||
|             int code = (int)AnalyticsCode.Unknown; | ||||
|             string info = msg; | ||||
|              | ||||
|             if (msg.Contains("msg\":")) | ||||
|             { | ||||
|                 var arr = msg.Split(new string[] {"msg\":"}, StringSplitOptions.RemoveEmptyEntries); | ||||
|                 if (arr.Length > 1) | ||||
|                 { | ||||
|                     info = arr[1]; | ||||
|                     if (info.StartsWith("\"")) info = info.Substring(1); | ||||
|                     if (info.EndsWith("\"}}")) info = info.Replace("\"}}", ""); | ||||
|                 } | ||||
|             } | ||||
|              | ||||
|             try | ||||
|             { | ||||
|                 var response = JsonConvert.DeserializeObject<JObject>(msg); | ||||
|                 if (response.TryGetValue("action", out var jAct)) | ||||
|                 patten = "action\":\""; | ||||
|                 if (msg.Contains(patten)) | ||||
|                 { | ||||
|                     if (jAct.ToString() == ActionName  | ||||
|                         && response.TryGetValue("data", out var jData) && jData is JObject data) | ||||
|                     idx = msg.IndexOf(patten, StringComparison.Ordinal) + patten.Length; | ||||
|                     string act = msg.Substring(idx, ActionName.Length); | ||||
|                     if (act == ActionName) | ||||
|                     { | ||||
|                         int code = -1; | ||||
|                         string message = msg; | ||||
|                         patten = "code\":"; | ||||
|                         patten2 = ",\"msg"; | ||||
|                         idx = msg.IndexOf(patten); | ||||
|                         idx2 = msg.IndexOf(patten2); | ||||
|                      | ||||
|                         if (data.TryGetValue("code", out var jCode)) | ||||
|                         len = idx2 - (idx + patten.Length); | ||||
|                         if (len > 0) | ||||
|                         { | ||||
|                             int.TryParse(jCode.ToString(), out code); | ||||
|                         } | ||||
|                         if (data.TryGetValue("msg", out var jMsg)) | ||||
|                         { | ||||
|                             message = jMsg.ToString(); | ||||
|                             string c = msg.Substring(idx + patten.Length, len); | ||||
|                             int.TryParse(c, out code); | ||||
|                         } | ||||
|                          | ||||
|                         var errorCode = (AnalyticsCode)code; | ||||
|                         switch (errorCode) | ||||
|                         // Catch target code to report errors | ||||
|                         switch ((AnalyticsCode)code) | ||||
|                         { | ||||
|                             case AnalyticsCode.Network_Lost: | ||||
|                             case AnalyticsCode.ERROR_API: | ||||
|                             case AnalyticsCode.ERROR_DNS: | ||||
|                             case AnalyticsCode.ERROR_ZIP: | ||||
|                             case AnalyticsCode.ERROR_LOAD_MARK: | ||||
|                             case AnalyticsCode.ERROR_RESPONSE: | ||||
|                             case AnalyticsCode.ERROR_CACHE_CONTROL: | ||||
|                             case AnalyticsCode.ERROR_DELETE_EXPIRED: | ||||
|                                 OnLoggerErrorEvent(code, message); | ||||
|                                 break;   | ||||
|                         } | ||||
|                             case AnalyticsCode.ERROR_LOAD_MARK: | ||||
|                             case AnalyticsCode.ERROR_DNS: | ||||
|                             case AnalyticsCode.ERROR_ZIP: | ||||
|                                 OnLoggerErrorEvent(code, info); | ||||
|                                 return; | ||||
|                         } | ||||
|                     } | ||||
|                 Debug.LogError($"{Tag} Parse callback Error"); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 Debug.LogError($"{Tag} Catch ex: {ex}\tJson:{msg}"); | ||||
|                 Analytics.LogCrashlytics($"{Tag} --- Json:{msg}  Ex:{ex}"); | ||||
|                 OnLoggerErrorEvent(code, info); | ||||
|             } | ||||
| 
 | ||||
|             string sap = "msg\":"; | ||||
|             OnLoggerErrorEvent((int)AnalyticsCode.Unknown,  | ||||
|                 msg.Substring(msg.IndexOf(sap, StringComparison.Ordinal) + sap.Length)); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|  | @ -392,6 +410,8 @@ namespace Guru | |||
|         /// <param name="errorInfo"></param> | ||||
|         private static void OnLoggerErrorEvent(int code, string errorInfo = "") | ||||
|         { | ||||
|             Debug.Log($"{Tag} --- OnLoggerErrorEvent: code:{code}\tinfo:{errorInfo}"); | ||||
|              | ||||
|             Dictionary<string, dynamic> parameters = new Dictionary<string, dynamic>() | ||||
|             { | ||||
|                 {"item_category", "error_event"}, | ||||
|  | @ -401,12 +421,18 @@ namespace Guru | |||
|             }; | ||||
|             if (!string.IsNullOrEmpty(errorInfo)) | ||||
|             { | ||||
|                 int len = 32; | ||||
|                 // if (errorInfo.Contains("\"")) errorInfo = errorInfo.Replace("\"", "\\\""); | ||||
|                  | ||||
|                 int len = 96; | ||||
|                 if (errorInfo.Length > len) errorInfo = errorInfo.TrimStart().Substring(0, len); | ||||
|                 parameters["err"] = errorInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 errorInfo = "empty error info"; | ||||
|             } | ||||
|              | ||||
|             Debug.Log($"{Tag} --- ErrorLogInfo:: code:{code}\tinfo:{errorInfo}"); | ||||
|             parameters["err"] = errorInfo; | ||||
|             Debug.Log($"{Tag} ------------ ErrorLogInfo:: code:{code}\tinfo:{errorInfo}"); | ||||
| 
 | ||||
|             // Only for firebase GA | ||||
|             Analytics.LogEvent("dev_audit", parameters, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue