Skip to content

Commit

Permalink
fix: close the call before attempting another (#1022)
Browse files Browse the repository at this point in the history
Close the response object before attempting the call to refresh the token.
  • Loading branch information
Chesire committed Jun 23, 2023
1 parent b46b199 commit 11ac751
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -27,15 +27,19 @@ class AuthRefreshInterceptor @Inject constructor(
) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val originRequest = chain.request()
val response = chain.proceed(originRequest)
val response = chain.proceed(chain.request())

return if (response.isAuthError) {
Timber.w("Response threw an auth error (${response.code()}), attempting to refresh")
try {
response.close()
} catch (ex: Exception) {
Timber.w(ex, "Unable to close response, carrying on")
}
val refreshResponse = runBlocking { repo.refresh() }
if (refreshResponse is AccessTokenResult.Success) {
chain.proceed(
originRequest
chain.request()
.newBuilder()
.header("Authorization", "Bearer ${repo.accessToken}")
.build()
Expand Down

0 comments on commit 11ac751

Please sign in to comment.