Added Force Update error 5005 (API too old).
This commit is contained in:
parent
03242eadd8
commit
e1c07f1741
|
@ -23,7 +23,7 @@ plugins {
|
|||
kotlin("android")
|
||||
}
|
||||
|
||||
libVersion = Version(1, 1, 2)
|
||||
libVersion = Version(1, 1, 3)
|
||||
|
||||
android()
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ plugins {
|
|||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
libVersion = Version(1, 1, 2)
|
||||
libVersion = Version(1, 1, 3)
|
||||
|
||||
android()
|
||||
|
||||
|
|
|
@ -297,11 +297,23 @@ internal class ApiManagerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `test force update`() = runBlockingTest {
|
||||
fun `test force update app too old`() = runBlockingTest {
|
||||
coEvery { backend.invoke<TestResult>(any()) } returns
|
||||
ApiResult.Error.Http(
|
||||
400, "",
|
||||
ApiResult.Error.ProtonData(ProtonForceUpdateHandler.ERROR_CODE_FORCE_UPDATE, "")
|
||||
ApiResult.Error.ProtonData(ProtonForceUpdateHandler.ERROR_CODE_FORCE_UPDATE_APP_TOO_OLD, "")
|
||||
)
|
||||
val result = apiManager.invoke { test() }
|
||||
assertTrue(result is ApiResult.Error)
|
||||
assertEquals(true, apiClient.forceUpdated)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test force update api too old`() = runBlockingTest {
|
||||
coEvery { backend.invoke<TestResult>(any()) } returns
|
||||
ApiResult.Error.Http(
|
||||
400, "",
|
||||
ApiResult.Error.ProtonData(ProtonForceUpdateHandler.ERROR_CODE_FORCE_UPDATE_API_TOO_OLD, "")
|
||||
)
|
||||
val result = apiManager.invoke { test() }
|
||||
assertTrue(result is ApiResult.Error)
|
||||
|
|
|
@ -24,7 +24,7 @@ plugins {
|
|||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
libVersion = Version(1, 1, 2)
|
||||
libVersion = Version(1, 1, 3)
|
||||
|
||||
dependencies {
|
||||
|
||||
|
|
|
@ -37,12 +37,18 @@ class ProtonForceUpdateHandler<Api>(private val apiClient: ApiClient) :
|
|||
error: ApiResult.Error,
|
||||
call: ApiManager.Call<Api, T>
|
||||
): ApiResult<T> {
|
||||
if (error is ApiResult.Error.Http && error.proton?.code == ERROR_CODE_FORCE_UPDATE)
|
||||
if (error is ApiResult.Error.Http && error.proton != null && error.proton.code in ERROR_CODE_FORCE_UPDATE) {
|
||||
apiClient.forceUpdate(error.proton.error)
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ERROR_CODE_FORCE_UPDATE = 5003
|
||||
const val ERROR_CODE_FORCE_UPDATE_APP_TOO_OLD = 5003
|
||||
const val ERROR_CODE_FORCE_UPDATE_API_TOO_OLD = 5005
|
||||
private val ERROR_CODE_FORCE_UPDATE = listOf(
|
||||
ERROR_CODE_FORCE_UPDATE_APP_TOO_OLD,
|
||||
ERROR_CODE_FORCE_UPDATE_API_TOO_OLD
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue