Hi all, I’ve been taking a look at Kotlin/Native f...
# kotlin-native
j
Hi all, I’ve been taking a look at Kotlin/Native for the past couple of days looking at the possibility of using it for iOS and Android app development.  At the moment I’m taking a look at executing a network request using Ktor. Just a simple login request. If successful the API returns an auth token. This case works great. My problem is if the request is unsuccessful (the username / password combination is incorrect, one of the fields wasn’t provided, etc.) the API returns a 400 response and some JSON with a reason as to why the request failed. At the moment the only thing I get is the Throwable which tells me the error code. Ideally I’d like to still decode the json in the response to present a more helpful error message.  tl;dr: How can I deserialise the response of a failed network request?
k
use HttpResponse as the response type
something like: val response = client.get<HttpResponse>("https://yoururl.com") val jsonText: String = response.readText() ... then parse jsonText
j
Perfect, got it working 😀 Thanks to both of you