Remove old authentication retry code

This commit is contained in:
Ryan Harg 2021-08-07 20:20:48 +02:00
parent 32ca977df2
commit 88b162b0f9
No known key found for this signature in database
GPG Key ID: 89106F3A84E6958C
3 changed files with 4 additions and 31 deletions

View File

@ -626,6 +626,7 @@ class MainActivity : AppCompatActivity() {
private fun incrementListenCount(track: Track?) { private fun incrementListenCount(track: Track?) {
track?.let { track?.let {
it.log("Incrementing listen count for track ${track.id}")
lifecycleScope.launch(IO) { lifecycleScope.launch(IO) {
try { try {
Fuel Fuel
@ -634,7 +635,8 @@ class MainActivity : AppCompatActivity() {
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.body(Gson().toJson(mapOf("track" to track.id))) .body(Gson().toJson(mapOf("track" to track.id)))
.awaitStringResponse() .awaitStringResponse()
} catch (_: Exception) { } catch (e: Exception) {
e.log()
} }
} }
} }

View File

@ -7,7 +7,6 @@ import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.FuelError import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.ResponseDeserializable import com.github.kittinunf.fuel.core.ResponseDeserializable
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult
import com.github.kittinunf.fuel.coroutines.awaitObjectResult
import com.github.kittinunf.result.Result import com.github.kittinunf.result.Result
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -92,37 +91,10 @@ class HttpUpstream<D : Any, R : OtterResponse<D>>(
val request = Fuel.get(mustNormalizeUrl(url)).apply { val request = Fuel.get(mustNormalizeUrl(url)).apply {
authorize(context) authorize(context)
} }
val (_, _, result) = request.awaitObjectResponseResult(GenericDeserializer<R>(type))
val (_, response, result) = request.awaitObjectResponseResult(GenericDeserializer<R>(type))
if (response.statusCode == 401) {
return retryGet(url)
}
result result
} catch (e: Exception) { } catch (e: Exception) {
Result.error(FuelError.wrap(e)) Result.error(FuelError.wrap(e))
} }
} }
private suspend fun retryGet(url: String): Result<R, FuelError> {
context?.let {
return try {
return if (http.refresh()) {
val request = Fuel.get(mustNormalizeUrl(url)).apply {
if (!Settings.isAnonymous()) {
header("Authorization", "Bearer ${oAuth.state().accessToken}")
}
}
request.awaitObjectResult(GenericDeserializer(type))
} else {
Result.Failure(FuelError.wrap(RefreshError))
}
} catch (e: Exception) {
Result.error(FuelError.wrap(e))
}
}
throw IllegalStateException("Illegal state: context is null")
}
} }

View File

@ -22,6 +22,5 @@ class SplashActivityTest {
val appContext = Shadows.shadowOf(ApplicationProvider.getApplicationContext<FFA>()) val appContext = Shadows.shadowOf(ApplicationProvider.getApplicationContext<FFA>())
expectThat(appContext.nextStartedActivity.component).isEqualTo(expectedIntent.component) expectThat(appContext.nextStartedActivity.component).isEqualTo(expectedIntent.component)
} }
} }
} }