Remove references to HTTP constants in favor of raw ints (#167)

This commit is contained in:
Andrew Haisting 2023-10-26 13:48:16 -05:00 committed by Álison Fernandes
parent fd9ba2550f
commit 865a99fd67
2 changed files with 5 additions and 9 deletions

View file

@ -8,7 +8,6 @@ import com.x8bit.bitwarden.data.auth.datasource.network.model.RegisterResponseJs
import com.x8bit.bitwarden.data.platform.datasource.network.model.toBitwardenError
import com.x8bit.bitwarden.data.platform.datasource.network.util.parseErrorBodyOrNull
import kotlinx.serialization.json.Json
import java.net.HttpURLConnection
class AccountsServiceImpl constructor(
private val accountsApi: AccountsApi,
@ -25,13 +24,10 @@ class AccountsServiceImpl constructor(
.recoverCatching { throwable ->
val bitwardenError = throwable.toBitwardenError()
bitwardenError.parseErrorBodyOrNull<RegisterResponseJson.CaptchaRequired>(
code = HttpURLConnection.HTTP_BAD_REQUEST,
code = 400,
json = json,
) ?: bitwardenError.parseErrorBodyOrNull<RegisterResponseJson.Invalid>(
codes = listOf(
HttpURLConnection.HTTP_BAD_REQUEST,
429,
),
codes = listOf(400, 429),
json = json,
) ?: bitwardenError.parseErrorBodyOrNull<RegisterResponseJson.Error>(
code = 429,

View file

@ -7,7 +7,6 @@ import com.x8bit.bitwarden.data.platform.datasource.network.util.base64UrlEncode
import com.x8bit.bitwarden.data.platform.datasource.network.util.parseErrorBodyOrNull
import com.x8bit.bitwarden.data.platform.util.DeviceModelProvider
import kotlinx.serialization.json.Json
import java.net.HttpURLConnection.HTTP_BAD_REQUEST
import java.util.UUID
class IdentityServiceImpl constructor(
@ -16,6 +15,7 @@ class IdentityServiceImpl constructor(
private val deviceModelProvider: DeviceModelProvider = DeviceModelProvider(),
) : IdentityService {
@Suppress("MagicNumber")
override suspend fun getToken(
email: String,
passwordHash: String,
@ -37,10 +37,10 @@ class IdentityServiceImpl constructor(
.recoverCatching { throwable ->
val bitwardenError = throwable.toBitwardenError()
bitwardenError.parseErrorBodyOrNull<GetTokenResponseJson.CaptchaRequired>(
code = HTTP_BAD_REQUEST,
code = 400,
json = json,
) ?: bitwardenError.parseErrorBodyOrNull<GetTokenResponseJson.Invalid>(
code = HTTP_BAD_REQUEST,
code = 400,
json = json,
) ?: throw throwable
}