Remove old authentication retry code
This commit is contained in:
parent
32ca977df2
commit
88b162b0f9
|
@ -626,6 +626,7 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
private fun incrementListenCount(track: Track?) {
|
||||
track?.let {
|
||||
it.log("Incrementing listen count for track ${track.id}")
|
||||
lifecycleScope.launch(IO) {
|
||||
try {
|
||||
Fuel
|
||||
|
@ -634,7 +635,8 @@ class MainActivity : AppCompatActivity() {
|
|||
.header("Content-Type", "application/json")
|
||||
.body(Gson().toJson(mapOf("track" to track.id)))
|
||||
.awaitStringResponse()
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
e.log()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.github.kittinunf.fuel.Fuel
|
|||
import com.github.kittinunf.fuel.core.FuelError
|
||||
import com.github.kittinunf.fuel.core.ResponseDeserializable
|
||||
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult
|
||||
import com.github.kittinunf.fuel.coroutines.awaitObjectResult
|
||||
import com.github.kittinunf.result.Result
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
|
@ -92,37 +91,10 @@ class HttpUpstream<D : Any, R : OtterResponse<D>>(
|
|||
val request = Fuel.get(mustNormalizeUrl(url)).apply {
|
||||
authorize(context)
|
||||
}
|
||||
|
||||
val (_, response, result) = request.awaitObjectResponseResult(GenericDeserializer<R>(type))
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
return retryGet(url)
|
||||
}
|
||||
|
||||
val (_, _, result) = request.awaitObjectResponseResult(GenericDeserializer<R>(type))
|
||||
result
|
||||
} catch (e: Exception) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,5 @@ class SplashActivityTest {
|
|||
val appContext = Shadows.shadowOf(ApplicationProvider.getApplicationContext<FFA>())
|
||||
expectThat(appContext.nextStartedActivity.component).isEqualTo(expectedIntent.component)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue