Hello guys. I am using ktor client and I can't fin...
# ktor
j
Hello guys. I am using ktor client and I can't find a way to handle response error.
a
Hey. What do you mean by a response error? If you mean some network error then you can wrap a client’s request call in
try/catch
block to handle the error.
j
@Aleksei Tirman [JB] I have introduced the try catch block but I want to know how to parse the error message returned by the API. Bringing it to context, I wrote the server side code and ensured that if any error occurs, a uniform error object is returned as response: data class Error( val status: Boolean = false, val message: String ) How do I have access to this object from the catch block?
Secondly, is there no way I can do that in the HttpClient configuration rather than repeating it in every endpoint?
a
What you are describing is not a server error so you can just deserialize a response to your data class using the ContentNegotiation plugin.
j
I have used ContentNegotiation on the serverside, how do I use it with an Android client?
a
j
Thanks