Skip to content

Commit 81f308e

Browse files
committed
[NDGL-17] refactor: Authenticator 토큰 갱신 로직 개선
- uuid null/empty 체크 추가 - mutex 내에서 토큰 갱신 및 저장을 원자적으로 수행 - 예외 발생 시 Timber 로깅 추가 - 에러 발생 시 null 반환으로 재시도 중단
1 parent c92ce31 commit 81f308e

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

data/core/src/main/java/com/yapp/ngdl/data/core/authenticator/NDGLAuthenticator.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import okhttp3.Authenticator
1111
import okhttp3.Request
1212
import okhttp3.Response
1313
import okhttp3.Route
14+
import timber.log.Timber
1415
import javax.inject.Inject
1516
import javax.inject.Provider
1617

@@ -40,20 +41,24 @@ class NDGLAuthenticator @Inject constructor(
4041
return null
4142
}
4243

43-
val uuid = runBlocking { localAuthDataSource.getUuid() }
44-
4544
val authResponse = runBlocking {
4645
mutex.withLock {
47-
ndglApi.get().login(LoginRequest(uuid))
48-
}
49-
}.getData()
46+
try {
47+
val uuid = localAuthDataSource.getUuid()
48+
if (uuid.isNullOrEmpty()) {
49+
return@withLock null
50+
}
5051

51-
runBlocking {
52-
localAuthDataSource.apply {
53-
setAccessToken(authResponse.accessToken)
54-
setUuid(authResponse.uuid)
52+
val response = ndglApi.get().login(LoginRequest(uuid)).getData()
53+
localAuthDataSource.setAccessToken(response.accessToken)
54+
localAuthDataSource.setUuid(response.uuid)
55+
response
56+
} catch (e: Exception) {
57+
Timber.e(e, "Failed to refresh token")
58+
null
59+
}
5560
}
56-
}
61+
} ?: return null
5762

5863
val newRequest = originRequest.newBuilder()
5964
.header(RETRY_HEADER, (retryCount + 1).toString())

0 commit comments

Comments
 (0)