Browse Source

1.修改log等级

2.处理拦截器崩溃问题
20241218TB223FC(测试jar包)
wangwanlei 8 months ago
parent
commit
a0c9bb75c0

+ 20
- 1
corelib/src/main/java/com/xhly/corelib/network/ResponseInterceptor.kt View File

@@ -10,6 +10,7 @@ import com.xhly.corelib.utils.GsonUtils
10 10
 import okhttp3.Interceptor
11 11
 import okhttp3.Request
12 12
 import okhttp3.Response
13
+import okhttp3.ResponseBody.Companion.toResponseBody
13 14
 import java.io.IOException
14 15
 import java.net.URLDecoder
15 16
 import java.net.URLEncoder
@@ -49,8 +50,26 @@ class ResponseInterceptor : Interceptor {
49 50
             originalResponse
50 51
         } catch (e: Exception) {
51 52
             e.printStackTrace()
52
-            chain.proceed(request)
53
+           try {
54
+               chain.proceed(request)
55
+           }catch (e:Exception){
56
+                  return createDefaultResponse()
57
+           }
53 58
         }
54 59
     }
60
+    fun createDefaultResponse(): Response {
61
+        // 创建默认的响应体内容
62
+        val responseBody = "Default Response Body" // 替换为您想要返回的默认响应体内容
55 63
 
64
+        // 创建默认的响应对象
65
+        val response = Response.Builder()
66
+            .code(200) // 替换为您想要的响应码
67
+            .message("Default Response Message") // 替换为您想要的响应消息
68
+            .protocol(okhttp3.Protocol.HTTP_1_1) // 替换为您想要的协议
69
+            .request(okhttp3.Request.Builder().url("http://example.com").build()) // 替换为请求对象
70
+            .body(responseBody.toResponseBody()) // 设置响应体
71
+            .build()
72
+
73
+        return response
74
+    }
56 75
 }

+ 1
- 1
corelib/src/main/java/com/xhly/corelib/utils/baseUtils.kt View File

@@ -104,7 +104,7 @@ fun Any.LogTag(): String {
104 104
 }
105 105
 
106 106
 fun Any.LogShow(s: String) {
107
-    LogUtils.e(LogTag(), s)
107
+    LogUtils.d(LogTag(), s)
108 108
 }
109 109
 
110 110
 fun Double.getScaleSize(

Loading…
Cancel
Save