Ver Fonte

feat: 网络错误提示

DoggyZhang há 3 dias atrás
pai
commit
9c736df179

+ 1 - 1
app/dependencies/releaseRuntimeClasspath.txt

@@ -171,7 +171,7 @@ com.gami.android:frame-locale:1.0.0
 com.gami.android:frame-log:1.0.1
 com.gami.android:frame-media:1.0.0
 com.gami.android:frame-mvvm:1.0.0
-com.gami.android:frame-network:1.0.1
+com.gami.android:frame-network:1.0.2
 com.gami.android:frame-oss:1.0.0
 com.gami.android:frame-router-annotation:1.0.0
 com.gami.android:frame-router-api:1.0.0

+ 17 - 24
app/src/main/java/com/adealink/weparty/commonui/toast/util/ToastUtil.kt

@@ -5,6 +5,9 @@ import androidx.annotation.StringRes
 import com.adealink.frame.aab.util.getCompatString
 import com.adealink.frame.base.AppBase
 import com.adealink.frame.base.IError
+import com.adealink.frame.base.NetworkHttpExecuteError
+import com.adealink.frame.base.NetworkHttpResBodyNullError
+import com.adealink.frame.base.NetworkHttpStatusNoSuccessError
 import com.adealink.frame.base.Rlt
 import com.adealink.frame.util.AppUtil
 import com.adealink.frame.util.runOnUiThread
@@ -60,27 +63,8 @@ fun showFailedToast(rlt: Rlt<*>) {
     }
 }
 
-fun showToast(error: IError, default: CharSequence? = null) {
-    if (error.msg.isNotEmpty()) {
-        if (AppBase.isRelease) {
-            //正式包不展示错误码
-            showToast(error.msg)
-        } else {
-            showToast(getCompatString(R.string.commonui_error_msg, error.msg, error.serverCode))
-        }
-        return
-    }
-
-    if (error.exception?.message?.isNotBlank() == true) {
-        showToast(error.exception!!.message!!)
-        return
-    }
-
-    if (default.isNullOrEmpty()) {
-        return
-    }
-
-    showToast(default)
+fun showToast(error: IError, default: CharSequence = getCompatString(R.string.common_failed)) {
+    showToast(getFailedMsg(error, default.toString()))
 }
 
 fun getFailedMsg(error: IError, default: String? = getCompatString(R.string.common_failed)): String {
@@ -92,9 +76,18 @@ fun getFailedMsg(error: IError, default: String? = getCompatString(R.string.comm
         }
     }
 
-    val exceptionMsg = error.exception?.message
-    if (exceptionMsg?.isNotBlank() == true) {
-        return exceptionMsg
+    //网络错误
+    if (error is NetworkHttpStatusNoSuccessError || error is NetworkHttpExecuteError || error is NetworkHttpResBodyNullError) {
+        return if (AppBase.isRelease) {
+            getCompatString(R.string.common_net_error)
+        } else {
+            "${getCompatString(R.string.common_net_error)} ${error.exception?.message}"
+        }
+    } else {
+        val exceptionMsg = error.exception?.message
+        if (exceptionMsg?.isNotBlank() == true) {
+            return exceptionMsg
+        }
     }
 
     if (default.isNullOrEmpty()) {

+ 1 - 1
gradle/libs.versions.toml

@@ -166,7 +166,7 @@ appleAppauth = "0.11.1"
 tiktok = "2.3.0"
 
 # frame
-frameBom = "1.0.1"
+frameBom = "1.0.3"
 
 framePush = "1.0.0"