https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Shadman

02/27/2024, 11:53 AM
Hi. Can anybody help me how to get the response body when request is 401. I use
ktor
and `ktorfit`:
Copy code
@POST("user/register")
suspend fun singUp(@Body signUpInputModel: SignUpInputModel): Response<SignUpModel>
I try everything .
errorBody
,
readAsText
,
bodyAsText
. my 401 hast a body in the log.
Copy code
fun singUp(userName: String, mobile: String, password: String) = viewModelScope.launch {
    authRepo.singUp(userName, mobile, password).onSuccess { response ->

        if (response.isSuccessful)
            _signupState.value = Loadable.Success(response.body()!!)
        else {
            response.errorBody()
        }
    }.onFailure {
        _signupState.value = Loadable.Error(it)
    }
}