Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-19 20:31:57 +05:00
parent c3850e7991
commit 195ffd4391
4 changed files with 53 additions and 2 deletions

View file

@ -18,6 +18,54 @@ sealed class ApiResponseError : Exception() {
val errorBody: String?,
) : ApiResponseError() {
fun isServerError(): Boolean = when (code) {
Code.OK,
Code.CREATED,
Code.ACCEPTED,
Code.NOT_MODIFIED,
Code.BAD_REQUEST,
Code.UNAUTHORIZED,
Code.PAYMENT_REQUIRED,
Code.FORBIDDEN,
Code.NOT_FOUND,
Code.METHOD_NOT_ALLOWED,
Code.NOT_ACCEPTABLE,
Code.PROXY_AUTHENTICATION_REQUIRED,
Code.REQUEST_TIMEOUT,
Code.CONFLICT,
Code.GONE,
Code.LENGTH_REQUIRED,
Code.PRECONDITION_FAILED,
Code.PAYLOAD_TOO_LARGE,
Code.URI_TOO_LONG,
Code.UNSUPPORTED_MEDIA_TYPE,
Code.RANGE_NOT_SATISFIABLE,
Code.EXPECTATION_FAILED,
Code.IM_A_TEAPOT,
Code.UNPROCESSABLE_ENTITY,
Code.LOCKED,
Code.FAILED_DEPENDENCY,
Code.TOO_EARLY,
Code.UPGRADE_REQUIRED,
Code.PRECONDITION_REQUIRED,
Code.TOO_MANY_REQUESTS,
Code.REQUEST_HEADER_FIELDS_TOO_LARGE,
Code.UNAVAILABLE_FOR_LEGAL_REASONS,
-> false
Code.INTERNAL_SERVER_ERROR,
Code.NOT_IMPLEMENTED,
Code.BAD_GATEWAY,
Code.SERVICE_UNAVAILABLE,
Code.GATEWAY_TIMEOUT,
Code.HTTP_VERSION_NOT_SUPPORTED,
Code.VARIANT_ALSO_NEGOTIATES,
Code.INSUFFICIENT_STORAGE,
Code.LOOP_DETECTED,
Code.NOT_EXTENDED,
Code.NETWORK_AUTHENTICATION_REQUIRED,
-> true
}
// TODO: extract Code from HttpException
// region Error Codes
enum class Code(val numericCode: Int) {

View file

@ -159,10 +159,11 @@ internal class TangemPayRequestPerformer @Inject constructor(
refreshToken = response.refreshToken,
refreshExpiresAt = response.refreshExpiresAt,
)
}.mapLeft { error ->
Timber.tag(TAG).e("Can not refresh auth tokens: $error")
if (error is VisaApiError.ServerUnavailable) error else VisaApiError.RefreshTokenExpired
}.onRight { tokens ->
tangemPayStorage.storeAuthTokens(customerWalletAddress = customerWalletAddress, tokens = tokens)
}.onLeft {
Timber.tag(TAG).e("Can not refresh auth tokens: $it")
}
}
}

View file

@ -18,6 +18,7 @@ internal class TangemPayErrorConverter @Inject constructor(
override fun convert(value: Throwable): VisaApiError {
return if (value is ApiResponseError.HttpException) {
if (value.isServerError()) return VisaApiError.ServerUnavailable
if (value.code == ApiResponseError.HttpException.Code.NOT_FOUND) return VisaApiError.NotPaeraCustomer
if (value.code == ApiResponseError.HttpException.Code.UNAUTHORIZED) return VisaApiError.RefreshTokenExpired

View file

@ -65,6 +65,7 @@ sealed class VisaApiError(
data object WithdrawalDataError : VisaApiError(104004003)
data object SignWithdrawError : VisaApiError(104004004)
data object WithdrawError : VisaApiError(104004005)
data object ServerUnavailable : VisaApiError(104004006)
companion object {
fun fromBackendError(backendErrorCode: Int): VisaApiError {