Selaa lähdekoodia

feat: 增加腾讯错误信息展示过滤

陈文艺 20 tuntia sitten
vanhempi
sitoutus
6308580abd

+ 14 - 2
Lanu/Manager/Room/LNRoomManager.swift

@@ -20,6 +20,18 @@ extension LNRoomManagerNotify {
 }
 
 
+func showTencentError(_ error: ErrorInfo) {
+    let items = error.message.components(separatedBy: ",")
+    for item in items {
+        let parts = item.components(separatedBy: ":")
+        if parts.first?.trimmingCharacters(in: .whitespaces) == "error_message" {
+            showToast(parts.dropFirst().joined(separator: ":").trimmingCharacters(in: .whitespaces))
+            return
+        }
+    }
+    showToast(error.message)
+}
+
 class LNRoomManager {
     static let shared = LNRoomManager()
     static let RoomNameMinInput = 2
@@ -87,7 +99,7 @@ extension LNRoomManager {
                     LNUserDefaults[.joinedRoomId] = roomId
                 case .failure(let errorInfo):
                     handler(nil)
-                    showToast(errorInfo.message)
+                    showTencentError(errorInfo)
                 }
             }
         }
@@ -101,7 +113,7 @@ extension LNRoomManager {
                     handler(true)
                 case .failure(let errorInfo):
                     handler(false)
-                    showToast(errorInfo.message)
+                    showTencentError(errorInfo)
                 }
             }
         }

+ 9 - 9
Lanu/Views/Room/ViewModel/LNRoomViewModel.swift

@@ -258,7 +258,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }
@@ -275,7 +275,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }
@@ -335,7 +335,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }
@@ -348,7 +348,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }
@@ -404,7 +404,7 @@ extension LNRoomViewModel {
                 case .success:
                     handler(true)
                 case .failure(let err):
-                    showToast(err.localizedDescription)
+                    showTencentError(err)
                     handler(false)
                 }
             }
@@ -415,7 +415,7 @@ extension LNRoomViewModel {
                 case .success:
                     unmute()
                 case .failure(let err):
-                    showToast(err.localizedDescription)
+                    showTencentError(err)
                     handler(false)
                 }
             }
@@ -434,7 +434,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }
@@ -447,7 +447,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }
@@ -508,7 +508,7 @@ extension LNRoomViewModel {
             case .success:
                 handler(true)
             case .failure(let err):
-                showToast(err.localizedDescription)
+                showTencentError(err)
                 handler(false)
             }
         }