NTP-31414 | Sohan | Fix for localhost being passed to api metrics (#14645)
This commit is contained in:
committed by
GitHub
parent
47f559074b
commit
d6493f80b6
@@ -29,6 +29,7 @@ import com.navi.common.network.models.RepoResult
|
||||
import com.navi.common.network.models.isSuccessWithData
|
||||
import com.navi.common.network.retrofit.RetrofitService as CommonRetrofitService
|
||||
import com.navi.common.utils.Constants.GZIP
|
||||
import com.navi.rr.common.models.ABSettings
|
||||
import com.navi.rr.common.network.retrofit.ResponseHandler
|
||||
import com.navi.rr.utils.cachemanager.CacheHandlerProxy
|
||||
import com.navi.rr.utils.ext.toGenericResponse
|
||||
@@ -179,15 +180,20 @@ constructor(
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun getCoinHomeScreenVariant(expName: String) =
|
||||
suspend fun getCoinHomeScreenVariant(
|
||||
expName: String,
|
||||
metricInfo: MetricInfo<RepoResult<ABSettings>>,
|
||||
) =
|
||||
cacheHandlerProxy.cacheManager.fetchAndCacheData(
|
||||
key = DBCacheConstants.COIN_HOME_SCREEN_VARIANT_CACHE_KEY,
|
||||
emitMultipleValues = false,
|
||||
fetchFromAlternativeSource = {
|
||||
responseHandler.handleResponse(
|
||||
retrofitService
|
||||
.fetchABExperiment(name = expName, header = ModuleName.LITMUS.name)
|
||||
.toGenericResponse()
|
||||
response =
|
||||
retrofitService
|
||||
.fetchABExperiment(name = expName, header = ModuleName.LITMUS.name)
|
||||
.toGenericResponse(),
|
||||
metricInfo = metricInfo,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -11,7 +11,9 @@ import com.navi.base.utils.orFalse
|
||||
import com.navi.coin.models.states.CoinRootState
|
||||
import com.navi.coin.repo.repository.CoinHomeScreenRepo
|
||||
import com.navi.coin.utils.constant.CoinHomeScreenConstants.COIN_HOME_SCREEN_VARIANT_EXPERIMENT_NAME
|
||||
import com.navi.common.checkmate.model.MetricInfo
|
||||
import com.navi.common.utils.isValidResponse
|
||||
import com.navi.rr.common.constants.COIN_HOME_SCREEN
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -28,7 +30,10 @@ class CoinHomeViewModel @Inject constructor(private val coinHomeScreenRepo: Coin
|
||||
init {
|
||||
launch {
|
||||
coinHomeScreenRepo
|
||||
.getCoinHomeScreenVariant(COIN_HOME_SCREEN_VARIANT_EXPERIMENT_NAME)
|
||||
.getCoinHomeScreenVariant(
|
||||
COIN_HOME_SCREEN_VARIANT_EXPERIMENT_NAME,
|
||||
metricInfo = MetricInfo.CoinMetric(screen = COIN_HOME_SCREEN, isNae = { false }),
|
||||
)
|
||||
.collect { response ->
|
||||
if (response.isValidResponse()) {
|
||||
_coinHomeScreenVariantState.update {
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.navi.rr.utils.ext
|
||||
import com.navi.base.utils.orElse
|
||||
import com.navi.common.network.models.GenericResponse
|
||||
import com.navi.rr.utils.getGsonBuilders
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import retrofit2.Response
|
||||
|
||||
fun <T> List<T>.secondOrNull(): T? {
|
||||
@@ -25,7 +26,22 @@ fun <T> T?.toJson(): String = getGsonBuilders().toJson(this).orElse("{}")
|
||||
fun Int.isOdd(): Boolean = this % 2 != 0
|
||||
|
||||
fun <T> Response<T>.toGenericResponse(): Response<GenericResponse<T>> {
|
||||
return Response.success(
|
||||
GenericResponse(statusCode = this.code(), message = this.message(), data = this.body())
|
||||
)
|
||||
when (code()) {
|
||||
in 200..299 -> {
|
||||
return Response.success(
|
||||
GenericResponse(
|
||||
statusCode = this.code(),
|
||||
message = this.message(),
|
||||
data = this.body(),
|
||||
),
|
||||
raw(),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
val errorResponse =
|
||||
GenericResponse<T>(statusCode = this.code(), message = this.message(), data = null)
|
||||
return Response.error(errorResponse.toJson().toResponseBody(null), raw())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user