Fix api timeout crash
This commit is contained in:
@@ -8,6 +8,7 @@ import com.naviapp.models.response.SuccessResponse
|
||||
import com.naviapp.network.ApiConstants
|
||||
import com.naviapp.network.ApiErrorTagType
|
||||
import kotlinx.coroutines.launch
|
||||
import java.lang.Exception
|
||||
|
||||
class OtpSharedViewModel(private val repository: OtpRepository = OtpRepository()) : BaseVM(false) {
|
||||
private val _otpVerified = MutableLiveData<Boolean?>()
|
||||
@@ -57,19 +58,23 @@ class OtpSharedViewModel(private val repository: OtpRepository = OtpRepository()
|
||||
|
||||
fun verifyOtpForEPFO(otpRequest: OtpRequest) {
|
||||
coroutineScope.launch {
|
||||
val response = repository.verifyOtpForEPFO(otpRequest)
|
||||
when (response.statusCode) {
|
||||
ApiConstants.API_SUCCESS_CODE -> _verifyOtpResponse.value =
|
||||
SuccessResponse(success = true)
|
||||
ApiConstants.API_WRONG_OTP -> _errorVerifyOtp.value = ApiErrorTagType.OTP_WRONG
|
||||
ApiConstants.API_EXPIRED_OTP -> _errorVerifyOtp.value =
|
||||
ApiErrorTagType.OTP_EXPIRED
|
||||
ApiConstants.API_TOO_MANY_REQUESTS -> _errorVerifyOtp.value =
|
||||
ApiErrorTagType.MAX_OTP_ATTEMPTS
|
||||
else -> {
|
||||
_errorVerifyOtp.value = ApiErrorTagType.SOMETHING_WENT_WRONG
|
||||
setErrorData(response.errors, response.error)
|
||||
try {
|
||||
val response = repository.verifyOtpForEPFO(otpRequest)
|
||||
when (response.statusCode) {
|
||||
ApiConstants.API_SUCCESS_CODE -> _verifyOtpResponse.value =
|
||||
SuccessResponse(success = true)
|
||||
ApiConstants.API_WRONG_OTP -> _errorVerifyOtp.value = ApiErrorTagType.OTP_WRONG
|
||||
ApiConstants.API_EXPIRED_OTP -> _errorVerifyOtp.value =
|
||||
ApiErrorTagType.OTP_EXPIRED
|
||||
ApiConstants.API_TOO_MANY_REQUESTS -> _errorVerifyOtp.value =
|
||||
ApiErrorTagType.MAX_OTP_ATTEMPTS
|
||||
else -> {
|
||||
_errorVerifyOtp.value = ApiErrorTagType.SOMETHING_WENT_WRONG
|
||||
setErrorData(response.errors, response.error)
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@ import okhttp3.OkHttpClient
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
abstract class BaseHttpClient(private val timeoutInSec: Long) {
|
||||
val baseHttpClientBuilder : OkHttpClient.Builder
|
||||
val baseHttpClientBuilder: OkHttpClient.Builder
|
||||
get() {
|
||||
val okHttpClientBuilder = OkHttpClient.Builder()
|
||||
with(okHttpClientBuilder) {
|
||||
connectTimeout(timeoutInSec, TimeUnit.SECONDS)
|
||||
writeTimeout(timeoutInSec, TimeUnit.SECONDS)
|
||||
readTimeout(timeoutInSec, TimeUnit.SECONDS)
|
||||
addInterceptor(headerInterceptor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user