Hiosdra
05/09/2020, 10:28 PMHiosdra
05/09/2020, 10:28 PM@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?pakoito
05/09/2020, 10:30 PMHiosdra
05/09/2020, 10:31 PMpakoito
05/09/2020, 10:32 PMpakoito
05/09/2020, 10:32 PMpakoito
05/09/2020, 10:33 PMpakoito
05/09/2020, 10:35 PMmapError
then handleErrorWith
pakoito
05/09/2020, 10:35 PMpakoito
05/09/2020, 10:36 PMHiosdra
05/09/2020, 10:58 PMval faceVectorsDto = !recognitionClient
.calculate(photoPart)
.mapError<Nothing, FaceVectorsDto, RepositoryError>(::identity)
.handleErrorWith({ IO.raiseError(ExternalFailure(it)) }, { IO.raiseError(it) })
Thanks, also for commenting in ticket 😄