I have retrofit repository with Tagless (IO) integration (from PR above):
@Multipart
@POST("/calculate")
fun calculate(@Part file: MultipartBody.Part): IO<Nothing, FaceVectorsDto>
and error ADT:
sealed class Error
...
sealed class RepositoryError : Error()
class ExternalFailure(val error: Throwable): RepositoryError()
and wish to handle exception flow into domain error
ExternalFailure
I have code in service calling above retrofit code:
override fun calculatePhoto(photo: ByteArray): IO<RepositoryError, FaceVectors> =
IO.fx<RepositoryError, FaceVectors> {
val photoPart = createPhotoPart(photo)
val faceVectorsDto = !recognitionClient
.calculate(photoPart)
.handleErrorWith({ IO.raiseError(ExternalFailure(it)) }, ::identity) //1*
faceVectorsDto.toDomainUnsafe()
}
// some space to get small breath 😛
In line with
//1*
I get type mismatch error in Intellij syntax highlightning
it is because
handleErrorWith
have signature:
fun <E, A, E2 : E> IOOf<E, A>.handleErrorWith(f: (Throwable) -> IOOf<E2, A>, fe: (E) -> IOOf<E2, A>): IO<E2, A>
And if
E
is
Nothing
(getting it from retrofit client), then
E2
must be
Nothing
too, because NOTHING 😛 is below
Nothing
in the hieratchy of inheritance.
// and another some space for some breath 😉
Simple fix will be making
E2
independent from
E
Other
handleErrorWith
is even worse for this case, because it has fixed
IO<Nothing, A>
type in arrow code
Is there maybe another way to handle such case?