Skip to content

Commit

Permalink
다른 변수로 할당해서 덮어쓰지 않고 새로 반환하기, try-catch문 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
stellar-halo committed Mar 14, 2024
1 parent 99bebdb commit ab96f49
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions app/src/main/java/com/sopetit/softie/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Qualifier
import javax.inject.Singleton
Expand Down Expand Up @@ -49,26 +50,29 @@ object RetrofitModule {
.build()
)
when (response.code) {
EXPIRED_TOKEN -> {
response.close()

EXPIRED_TOKEN -> try {
runBlocking {
refreshTokenRepository.postRefreshToken().onSuccess { accessToken ->
refreshTokenRepository.setAccessToken(accessToken.accessToken)
response = chain.proceed(
request
.newBuilder()
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.addHeader(
AUTHORIZATION,
BEARER + localDataSource.accessToken
)
.build()
)
}
}
response.close()

val newRequest = chain.request()
var newResponse = chain.proceed(
newRequest
.newBuilder()
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.addHeader(AUTHORIZATION, BEARER + localDataSource.accessToken)
.build()
)
return@Interceptor newResponse
} catch (t: Throwable) {
Timber.e(t.message)
}
}
response
return@Interceptor response
}

@Provides
Expand Down

0 comments on commit ab96f49

Please sign in to comment.