I am using ktor with ContentNegotiation. What is t...
# server
k
I am using ktor with ContentNegotiation. What is the idiomatic way to handle the unchecked exceptions you can get when retrieving a response using ktor client? example code
val responseData: ReservedCitizenResponse = response.body()
. If there is something wrong in the response body this will just crash with an JsonDecodingException as an unchecked exception. It would be nice if the .body() function returned a Result monad so you could handle the cases of successful and unsuccessful serialization.
val responseData: ReservedCitizenResponse = try {response.body() } catch (e: Exception) { return Result.failure(NHNInvalidResponseBodyException("Json response does not match expected fields\ne${e.message}")) }
This is how I have solved it for now, which is not very elegant, but does allow me to return early.
👎 1
l
You can use StatusPages if you want to return a generic error.