我正在尝试学习开发android应用程序,并且正在尝试实现最新的方法。所以我使用尽可能多的jetpack库。(Dagger-Hilt,Coroutines,Retrofit等)
这是我的问题:
我有一个用于依赖注入的AppModule对象。
下面是我的改进对象:
@Singleton
@Provides
fun provideConverterApi(): ConverterAPI {
return Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ConverterAPI::class.java)
}我如何从那里获取错误消息,或者例如我需要查看我用于请求的url,我该如何做呢?
发布于 2021-11-04 22:41:19
您做得很好,要为您的网络调用添加记录器,请使用以下方法:
.addConverterFactory(GsonConverterFactory.create())
.addInterceptor(HttpLoggingInterceptor().apply {
level = if (DEBUG) BODY else NONE
})
.build()发布于 2021-11-05 02:55:39
基于@Amjad Alwareh,记得添加HTTP日志拦截器的依赖项。
implementation "com.squareup.okhttp3:logging-interceptor:${okHttpVersion}", // 3.12.1 or other version也许DEBUG应该是BuildConfig.DEBUG
https://stackoverflow.com/questions/69846431
复制相似问题