Modify: 添加网络请求日志拦截器(带UI)

This commit is contained in:
Quyunshuo
2020-08-29 17:13:05 +08:00
parent bc708aff5d
commit bf245d118f
7 changed files with 20 additions and 5 deletions

View File

@ -44,4 +44,6 @@ dependencies {
kapt GitHub.GlideCompiler
kapt GitHub.ARouteCompiler
kapt GitHub.EventBusAPT
debugImplementation GitHub.Chuck
}

View File

@ -1,7 +1,9 @@
package com.quyunshuo.common.net
import com.quyunshuo.base.BaseApplication
import com.quyunshuo.base.BuildConfig
import com.quyunshuo.common.constant.NetUrl
import com.readystatesoftware.chuck.ChuckInterceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
@ -32,10 +34,11 @@ object NetServiceCreator {
private val okHttpClient by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
OkHttpClient.Builder()
.connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS) // 连接超时
.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS) // 读取超时
.addInterceptor(if (BuildConfig.DEBUG) BODY else NONE) // 请求日志拦截器
.retryOnConnectionFailure(true) // 失败重连
.connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS) // 连接超时
.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS) // 读取超时
.addInterceptor(if (BuildConfig.DEBUG) BODY else NONE) // 请求日志拦截器
.addInterceptor(ChuckInterceptor(BaseApplication.context)) // 请求日志拦截器(UI)
.retryOnConnectionFailure(true) // 失败重连
.build()
}