Updated on 2026-08-14

This commit is contained in:
Tangem 2022-04-18 17:27:28 +03:00
parent 65a55cb5e3
commit 268b74cb0e
4 changed files with 49 additions and 11 deletions

View file

@ -10,19 +10,23 @@ import com.tangem.common.module.ModuleMessage
sealed interface DomainModuleMessage : ModuleMessage
sealed class DomainError(
override val code: Int,
subCode: Int,
override val message: String,
override val data: Any?,
) : DomainModuleMessage, ModuleError {
override val code: Int = ERROR_CODE_DOMAIN + subCode
companion object {
const val CODE_ADD_CUSTOM_TOKEN = 1000
// base code used for all error in the module
const val ERROR_CODE_DOMAIN = 10000
const val ERROR_CODE_ADD_CUSTOM_TOKEN = 100
// const val CODE_ANY_OTHER = 200..299
}
}
sealed class AddCustomTokenError(
subCode: Int = 0
) : DomainError(CODE_ADD_CUSTOM_TOKEN + subCode, this::class.java.simpleName, null) {
) : DomainError(ERROR_CODE_ADD_CUSTOM_TOKEN + subCode, this::class.java.simpleName, null) {
object FieldIsEmpty : AddCustomTokenError()
object FieldIsNotEmpty : AddCustomTokenError()

View file

@ -5,6 +5,8 @@ import com.tangem.common.services.performRequest
import com.tangem.network.common.AddHeaderInterceptor
import com.tangem.network.common.CacheControlHttpInterceptor
import com.tangem.network.common.createRetrofitInstance
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
[REDACTED_AUTHOR]
@ -59,22 +61,22 @@ class CoinsRoute : TangemTechRoute {
suspend fun prices(
currency: String,
ids: List<String>
): Result<Coins.PricesResponse> {
return performRequest { api.coinsPrices(currency, ids) }
): Result<Coins.PricesResponse> = withContext(Dispatchers.IO) {
performRequest { api.coinsPrices(currency, ids) }
}
suspend fun checkAddress(
contractAddress: String,
networkId: String? = null
): Result<Coins.CheckAddressResponse> {
return performRequest { api.coinsCheckAddress(contractAddress, networkId) }
): Result<Coins.CheckAddressResponse> = withContext(Dispatchers.IO) {
performRequest { api.coinsCheckAddress(contractAddress, networkId) }
}
suspend fun currencies(): Result<Coins.CurrenciesResponse> {
return performRequest { api.coinsCurrencies() }
suspend fun currencies(): Result<Coins.CurrenciesResponse> = withContext(Dispatchers.IO) {
performRequest { api.coinsCurrencies() }
}
suspend fun tokens(): Result<Coins.TokensResponse> {
return performRequest { api.coinsTokens() }
suspend fun tokens(): Result<Coins.TokensResponse> = withContext(Dispatchers.IO) {
performRequest { api.coinsTokens() }
}
}

View file

@ -0,0 +1,23 @@
package com.tangem.network.common
import com.tangem.common.module.ModuleError
import com.tangem.common.module.ModuleMessage
/**
[REDACTED_AUTHOR]
*/
sealed interface NetworkModuleMessage : ModuleMessage
sealed class NetworkError(
subCode: Int,
override val message: String,
override val data: Any?,
) : NetworkModuleMessage, ModuleError {
override val code: Int = ERROR_CODE_NETWORK + subCode
companion object {
// base code used for all error in the module
const val ERROR_CODE_NETWORK = 20000
// const val CODE_ANY_OTHER = 100..199
}
}

View file

@ -0,0 +1,9 @@
package com.tangem.network.common
/**
[REDACTED_AUTHOR]
*/
interface NetworkInternalException
sealed class NetworkException(message: String?) : Throwable(message), NetworkInternalException {
}