Hi folks. I'm currently using ktor-client with arrow-kt, and I have an interface like this
interface MyApi {
// NetworkError is a sealed interface
suspend fun getFoo(): Either<NetworkError, FooDto>
}
My intention is that in case there is a request exception or response error,
getFoo()
returns
Left
. Thanks to
createClientPlugin()
, I successfully transformed response errors to
NetworkError
but have yet to transform request exceptions. So currently
MyApiImpl
is looking like below, which is repetitive and error-prone
class MyApiImpl(val client: HttpClient) : MyApi {
override suspend fun getFoo() = Either.catch {
client.get("foo")
}
.mapLeftNetworkError()
}
My question is, is there any way I get rid of
Either.catch { ... }.mapLeftNetworkError()
expression by just writing
client.get("foo")
?