|
@@ -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
|
}
|