rcd27
12/22/2022, 7:26 AMEither.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"simon.vergauwen
12/22/2022, 7:50 AMhandleErrorWith { e ->
when(e) {
ExternalApiError.NotFound -> emptyListOf<SourceSnippet>().right()
else -> e.left()
}
}simon.vergauwen
12/22/2022, 7:51 AMhandleError { _ -> emptyListOf<SourceSnippet>() }rcd27
12/22/2022, 7:54 AM