T
T
Tsuzukeru2021-02-15 19:30:56
Android
Tsuzukeru, 2021-02-15 19:30:56

Why doesn't Rerofit write the answer to the log?

I use Retrofit to send asynchronous requests in conjunction with RxJava.

Client class declaration:

object NasaApiClient {
private const val NASA_BASE_URL="https://images-api.nasa.gov/"

fun getClient(): NasaApiService {

    val logging = HttpLoggingInterceptor()
    logging.level = HttpLoggingInterceptor.Level.BODY

    val okHttpClient =  OkHttpClient.Builder()
        .addInterceptor(logging)
        .readTimeout(20, TimeUnit.SECONDS)
        .build()

    val gson = GsonBuilder().create()

    val retrofit = Retrofit.Builder()
        .baseUrl(NASA_BASE_URL)
        .client(okHttpClient)
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build()

    return retrofit.create(NasaApiService::class.java)
 }
}


Get request and associated Rx method
interface NasaApiService {
  @GET("search")
  fun mediaInfo(@Query("nasa_id")nasa_id:String): Single<MediaDetail>
}

fun fetchMediaDetails(nasaId:String){
    _networkState.postValue(NetworkState.LOADING)

    try {
        compositeDisposable.add(
        apiService.mediaInfo(nasaId)
            .observeOn(Schedulers.io())
            .subscribeOn(Schedulers.io())
            .subscribe ({
                Log.e("MediaDetail",it.toString())
                _downloadedMediaDetailsResponse.postValue(it)
                _networkState.postValue(NetworkState.LOADED)
            },{
                _networkState.postValue(NetworkState.ERROR)
                Log.e("MovieDetailsDataSource", it.message.toString())
            })
        )
    }
    catch (e: Exception){
        Log.e("MediaDetailsDataSource", e.message.toString())
    }
}


Retrofit doesn't log anything. Why is this happening? LoggingInterceptor is connected.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tsudzukeru, 2021-02-16
@Tsuzukeru

After updating the version of Retrofit and OkHttp - everything works!

//Retrofit
    def retrofit_version = "2.9.0"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question