File tree Expand file tree Collapse file tree
data/core/src/main/java/com/yapp/ngdl/data/core/authenticator Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import okhttp3.Authenticator
1111import okhttp3.Request
1212import okhttp3.Response
1313import okhttp3.Route
14+ import timber.log.Timber
1415import javax.inject.Inject
1516import 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())
You can’t perform that action at this time.
0 commit comments