Christopher Mederos
08/16/2023, 6:47 PMexpectSuccess = true
and a global exception handler for ClientRequestExceptions?
• using expectSuccess = true
and using the client inside a try/catch block
• using expectSuccess = false
and checking the response.status
and adding control flow for success/failure statuses accordingly?
• something else??
I'm also curious what people's opinions are for choosing an interface for downstream functions that use the results of network requests. I've seen a variety of thoughts including -
• Using sealed interfaces with Success & Failure objects that wrap the response
• Using nulls to represent non-2xx responses
• Wrapping client request functions with "safe" extension functions that catches & handle exceptions... then returning either nulls or Success/Failure objects
• Have the control flow represent the happy path only, with any exceptions being thrown by the ktor client istelf, and eventually handled at a top level exception handlerRob Murdock
08/16/2023, 7:34 PMRob Murdock
08/16/2023, 7:38 PMShahzad Ansari
08/16/2023, 8:14 PMStylianos Gakis
08/16/2023, 8:27 PMRob Murdock
08/16/2023, 8:31 PMShahzad Ansari
08/16/2023, 8:38 PMChristopher Mederos
08/16/2023, 9:03 PMJavier
08/16/2023, 9:56 PMsuspend fun main() {
val either: NetworkEither<ErrorDTO, DogDTO> = client.get("dog/$code").body()
either.fold(...)
}
@Serializable data class DogDTO(val id: Int, val name: String, val age: Int)
@Serializable data class ErrorDTO(val message: String)
MR3Y
09/18/2023, 11:21 PMJavier
09/21/2023, 5:41 PM