Pārlūkot izejas kodu

添加网络异常日志记录和提示

Frankensteinly 8 mēneši atpakaļ
vecāks
revīzija
2bf5705648

+ 6 - 0
app/src/main/java/com/grkj/iscs/util/NetHttpManager.kt

@@ -20,6 +20,7 @@ import com.grkj.iscs.model.UrlConsts
 import com.grkj.iscs.model.UrlConsts.LOGIN_CARD
 import com.grkj.iscs.util.log.LogUtil
 import okhttp3.logging.HttpLoggingInterceptor
+import java.io.IOException
 import java.net.SocketTimeoutException
 import java.util.concurrent.TimeUnit
 
@@ -58,6 +59,11 @@ class NetHttpManager {
                 }
                 true
             }
+            .exceptionListener { task: HttpTask<*>, error: IOException? ->
+                LogUtil.e("Network request exception : ${error?.message}")
+                ToastUtils.tip(error?.message)
+                true
+            }
             .config {
                 it.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
             }