https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
e

Emirhan Emmez

08/02/2022, 11:06 AM
Hello, why is my interceptor not proceeding request?
Copy code
class TokenInterceptor @Inject constructor(
    private val preferencesRepository: PreferencesRepository,
    private val cognitoRepository: CognitoRepository
) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        return runBlocking {
            val request = chain.request().newBuilder().build()

            if (preferencesRepository.isTokenExpired()) {
                cognitoRepository.login(
                    number = null,
                    password = null,
                    refreshToken = preferencesRepository.getRefreshToken(),
                    loginType = CognitoRepository.LoginType.RefreshToken
                ).collect()
            }

            chain.proceed(request)
        }
    }
}
j

jessewilson

08/02/2022, 11:49 AM
Not enough to diagnose here
Executable test case?
Also if you're using the same OkHttpClient inside an interceptor, be careful about hitting your dispatcher limits
Highly recommend only doing blocking calls inside interceptors, not suspending calls
e

Emirhan Emmez

08/02/2022, 12:21 PM
I want to write a token interceptor do you have any example?
j

jessewilson

08/02/2022, 12:32 PM
Not handy
maybe it may be generating an exception in preferences Repository#isTokenExpired that is not returning true to make the new request
e

Emirhan Emmez

08/02/2022, 5:36 PM
no it is returning true and also login get success response but i will look that medium article thx
4 Views