I'm working through real-world-android-by-tutorials Chapter 4.4 Interceptors, Im following the code as far as I can see and am getting an error "Variable 'interceptedRequest' must be initialized " adding in the code block from "Handling valid tokens"
override fun intercept(chain: Interceptor.Chain): Response {
// Replace with your code
val token = preferences.getToken()
val tokenExpirationTime =
Instant.ofEpochSecond(preferences.getTokenExpirationTime())
val request = chain.request()
// if(chain.request().headers[NO_AUTH_HEADER] != null) return
// chain.proceed()
val interceptedRequest: Request
if(tokenExpirationTime.isAfter(Instant.now())){
interceptedRequest =
chain.createAuthenticatedRequest(token)
}else{
}
return chain.proceedDeletingTokenIfUnauthorized(interceptedRequest)
//return chain.proceed(chain.request())
}
on the 17th line the method being called "chain.proceedDeletingTokenIfUnauthorized" and being passed "interceptedRequest", its throwing that error 'Variable 'interceptedRequest' must be initialized' but not sure why, the code is exactly what it appears as in the instruction. Maybe Im just getting poor vision, but I've tried invoking the "val" interceptedRequest(), but it doesnt like that, "initialized" seems like it is expecting to be assigned...
any help is greatly appreciated, I'll keep looking at it, I hope I do not need glasses. TIA