我如何处理改造错误或获得 url 检测问题的请求
How can i handle retrofit errors or get url request for to detect problems
我正在尝试学习开发 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,我该怎么做?
你做得很好,使用这种方式为你的网络调用添加一个记录器:
.addConverterFactory(GsonConverterFactory.create())
.addInterceptor(HttpLoggingInterceptor().apply {
level = if (DEBUG) BODY else NONE
})
.build()
基于@Amjad Alwareh,记得添加HTTP日志拦截器的依赖
implementation "com.squareup.okhttp3:logging-interceptor:${okHttpVersion}", // 3.12.1 or other version
也许 DEBUG
应该是 BuildConfig.DEBUG
我正在尝试学习开发 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,我该怎么做?
你做得很好,使用这种方式为你的网络调用添加一个记录器:
.addConverterFactory(GsonConverterFactory.create())
.addInterceptor(HttpLoggingInterceptor().apply {
level = if (DEBUG) BODY else NONE
})
.build()
基于@Amjad Alwareh,记得添加HTTP日志拦截器的依赖
implementation "com.squareup.okhttp3:logging-interceptor:${okHttpVersion}", // 3.12.1 or other version
也许 DEBUG
应该是 BuildConfig.DEBUG