Adding HttpResponseValidator ``` HttpRespon...
# ktor
m
Adding HttpResponseValidator
Copy code
HttpResponseValidator {
            validateResponse { response ->
                val body = Json.parseToJsonElement(response.bodyAsText())
                val map = body.jsonObject.toMap()
                if (map["status"].toString() != "\"${Status.SUCCESS.status}\"") {
                    throw Exception("API didn't return success")
                }
            }
        }
Gets me
io.ktor.serialization.ContentConvertException: No suitable converter found for TypeInfotype=class asia.zeals.mobile.android.models.responses.HomeResponse (Kotlin reflection is not available), reifiedType=class asia.zeals.mobile.android.models.responses.HomeResponse, kotlinType=asia.zeals.mobile.android.models.responses.HomeResponse (Kotlin reflection is not available))
Commenting out the HttpResponseValidator, I don’t get the exception anymore. Is there anything else I’m supposed to do in the validator? I do have
Copy code
@Serializable
data class HomeResponse(
    val status: String,
    val data: HomeSetData? = null
)
a
The problem is that the
response.bodyAsText()
call inside the
validateResponse
consumes the response body so it becomes empty anywhere else. This is a know issue (KTOR-4225).
👍 1
117 Views