繁体   English   中英

我如何处理改造错误或获取 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM