NTP-7163 | Fix api actualLatency and error title (#13107)

This commit is contained in:
shankar yadav
2024-10-15 16:27:37 +05:30
committed by GitHub
parent 9257020b13
commit a6210fdac1
4 changed files with 78 additions and 14 deletions

View File

@@ -16,6 +16,8 @@ import com.navi.common.checkmate.model.MetricInfo
import com.navi.common.checkmate.model.MetricSource
import com.navi.common.checkmate.model.SessionDetails
import com.navi.common.checkmate.utils.getEventNameWithVerticalPrefix
import com.navi.common.checkmate.utils.getLocalErrorDescription
import com.navi.common.checkmate.utils.getLocalErrorTitle
import com.navi.common.network.models.GenericResponse
import com.navi.common.network.models.RepoResult
import retrofit2.Response
@@ -152,23 +154,30 @@ object CheckMateManager {
val apiLatency =
apiResponse?.raw()?.receivedResponseAtMillis.orZero() -
apiResponse?.raw()?.sentRequestAtMillis.orZero()
val httpStatusCode = apiResponse?.raw()?.code.orZero()
recordNetworkEvent(
metricInfo = metricInfo,
statusCode = handledResponse.statusCode.orZero(),
actualLatency = apiLatency,
networkLatency = actualLatency,
statusCode = handledResponse.statusCode ?: httpStatusCode,
actualLatency = actualLatency,
networkLatency = apiLatency,
isNae = metricInfo.isNae(handledResponse),
httpStatusCode = apiResponse?.raw()?.code.orZero(),
httpStatusCode = httpStatusCode,
endpoint = apiResponse?.raw()?.request?.url.toString(),
errorCode = handledResponse.errors?.firstOrNull()?.code.orEmpty(),
errorTitle =
handledResponse.errors?.firstOrNull()?.title?.ifBlank {
handledResponse.error?.message.orEmpty()
} ?: EMPTY,
getLocalErrorTitle(
handledResponse.errors?.firstOrNull()?.title?.ifBlank {
handledResponse.error?.message.orEmpty()
} ?: EMPTY,
httpStatusCode
),
errorDes =
handledResponse.errors?.firstOrNull()?.message?.ifBlank {
handledResponse.error?.description.orEmpty()
} ?: EMPTY,
getLocalErrorDescription(
handledResponse.errors?.firstOrNull()?.message?.ifBlank {
handledResponse.error?.description.orEmpty()
} ?: EMPTY,
httpStatusCode
),
exception =
handledResponse.error?.exception?.ifBlank {
handledResponse.errors?.firstOrNull()?.logMessage.orEmpty()

View File

@@ -10,9 +10,20 @@ package com.navi.common.checkmate.utils
import android.content.Context
import android.os.BatteryManager
import android.os.StatFs
import com.navi.base.AppServiceManager
import com.navi.base.utils.orZero
import com.navi.common.R
import com.navi.common.checkmate.model.SessionDetails
import com.navi.common.model.ModuleNameV2
import com.navi.common.network.ApiConstants.API_CODE_CONNECT_EXCEPTION
import com.navi.common.network.ApiConstants.API_CODE_ERROR
import com.navi.common.network.ApiConstants.API_CODE_SOCKET_TIMEOUT
import com.navi.common.network.ApiConstants.API_CODE_UNKNOWN_HOST
import com.navi.common.network.ApiConstants.API_ERROR_PEER_UNVERIFIED
import com.navi.common.network.ApiConstants.API_WRONG_ERROR_RESPONSE
import com.navi.common.network.ApiConstants.IO_EXCEPTION_ERROR
import com.navi.common.network.ApiConstants.NO_INTERNET
import com.navi.common.utils.EMPTY
import com.navi.common.utils.log
import java.io.BufferedReader
import java.io.InputStreamReader
@@ -261,3 +272,40 @@ suspend fun getCurrentSessionMetrics(context: Context) =
memory = getMemoryUsagePercentage(),
storage = getStorageUsage(context)
)
fun getLocalErrorTitle(title: String, statusCode: Int): String {
if (title.isNotBlank()) return title
return when (statusCode) {
NO_INTERNET,
API_CODE_CONNECT_EXCEPTION,
API_CODE_UNKNOWN_HOST ->
AppServiceManager.application.getString(R.string.no_internet_connection)
API_CODE_ERROR,
API_WRONG_ERROR_RESPONSE,
API_ERROR_PEER_UNVERIFIED,
IO_EXCEPTION_ERROR,
API_CODE_SOCKET_TIMEOUT ->
AppServiceManager.application.getString(R.string.something_went_wrong)
else -> EMPTY
}
}
fun getLocalErrorDescription(description: String, statusCode: Int): String {
if (description.isNotBlank()) return description
return when (statusCode) {
NO_INTERNET,
API_CODE_CONNECT_EXCEPTION,
API_CODE_UNKNOWN_HOST ->
AppServiceManager.application.getString(
R.string.check_internet_connectivity_and_try_again
)
API_CODE_ERROR,
API_WRONG_ERROR_RESPONSE,
API_ERROR_PEER_UNVERIFIED,
IO_EXCEPTION_ERROR,
API_CODE_SOCKET_TIMEOUT -> AppServiceManager.application.getString(R.string.technical_issue)
else -> EMPTY
}
}

View File

@@ -349,14 +349,20 @@ object CommonUtils {
val errorMessage = ErrorMessage()
errorMessage.exception = exception.message
if (!isNetworkAvailable() || exception is ConnectException) {
errorMessage.message = AppServiceManager.application.getString(R.string.no_internet)
errorMessage.message =
AppServiceManager.application.getString(R.string.no_internet_connection)
errorMessage.description =
AppServiceManager.application.getString(R.string.no_internet_connection_description)
AppServiceManager.application.getString(
R.string.check_internet_connectivity_and_try_again
)
errorMessage.statusCode = ApiConstants.NO_INTERNET
} else if (exception is UnknownHostException) {
errorMessage.message = AppServiceManager.application.getString(R.string.no_internet)
errorMessage.message =
AppServiceManager.application.getString(R.string.no_internet_connection)
errorMessage.description =
AppServiceManager.application.getString(R.string.no_internet_connection_description)
AppServiceManager.application.getString(
R.string.check_internet_connectivity_and_try_again
)
errorMessage.statusCode = API_CODE_UNKNOWN_HOST
} else if (exception is JsonParseException) {
errorMessage.message =

View File

@@ -226,6 +226,7 @@ object Constants {
const val CONTENT_SIZE_IN_KB = "content_size_kb"
const val REQUEST_BODY = "request_body"
const val API_METRIC_EVENT = "dev_api_metric_event"
const val NETWORK_CONNECTIVITY_CHECKER = "dev_network_connectivity_checker"
const val IS_UPI_APP_AVAILABLE = "isUpiAppAvailable"
const val LIST_OF_INSTALLED_UPI_APPS = "LIST_OF_INSTALLED_UPI_APPS"
const val ANIMATION_DURATION_IN_MILLIS = 400