Hello folks, I have an api that returns error body...
# ktor
k
Hello folks, I have an api that returns error body with the correct error information when a bad request is sent. For eg I get status code 400 and the following body -
Copy code
{
  "errorCode": 1011,
  "errorMessage": "Unable to get Child information"
}
Now when I am writing a ktor client in a multi-platform module for this, I catch this in a response validator like -
Copy code
HttpResponseValidator {
            validateResponse {
                val statusCode = it.status.value
                when (statusCode) {
                    in 300..399 -> print(it.content.toString())
                    in 400..499 -> {
                        print(it.content.toString())
                        throw ClientRequestException(it)
                    }
                    in 500..599 -> print(it.content.toString())
                }
            }

            handleResponseException {
                print(it.message)
            }
        }
My query here is I am not able to access the response error body in either validateResponse or handleResponseException. Is there a way i can catch and parse that to get the actual error sent by server?
👀 1