Greetings. We wrap all "external API calls` in
Either.catch
(since we can not control the network layer of external libs, and moreover they throw exceptions). Then we map
left
block to our domain errors. The question is: is it OK to apply
.fold
functor to
Either
in case, when
Left
can hold an actual result we need? The code seems like that:
...
.fold(
ifLeft = {
when (it) {
ExternalApiError.NotFound -> emptyListOf<SourceSnippet>().right()
}
},
ifRight = { it.right() },
)
So here, when we got an external error, we treat it like
nothing found
, but this is "green way"