Hi where am i going wrong? :man-facepalming:
# arrow
t
Hi where am i going wrong? 🤦‍♂️
Im investigating
Copy code
api platform("io.arrow-kt:arrow-stack:1.1.3-alpha.37")
api "io.arrow-kt:arrow-core"
api 'io.arrow-kt:arrow-core-retrofit'
and have the following to test out both
Either
and
ResponseE
my code resembles this...
Copy code
interface DiscogsDataApi {

    suspend fun searchE(accessToken: String = ACCESS_TOKEN, options: Map<String, String>): ResponseE<NetworkException, Response<SearchResponse>>
    suspend fun search(accessToken: String = ACCESS_TOKEN, options: Map<String, String>): Either<NetworkException, Response<SearchResponse>>
}

interface DiscogsApi {

    @GET("database/search")
    suspend fun search(@Header(HEADER_AUTHORISATION) accessToken: String, @QueryMap options: Map<String, String>): Response<SearchResponse>
Copy code
@GET("database/search")
    suspend fun searchE(@Header(HEADER_AUTHORISATION) accessToken: String, @QueryMap options: Map<String, String>): ResponseE<NetworkException, Response<SearchResponse>>

}
and this...
Copy code
class DiscogsRepository @Inject constructor(private val service: DiscogsApi) : DiscogsDataApi {

    override suspend fun searchE(accessToken: String, options: Map<String, String>): ResponseE<NetworkException, Response<SearchResponse>> = service.searchE(accessToken, options)

    override suspend fun search(accessToken: String, options: Map<String, String>): Either<NetworkException, Response<SearchResponse>> = withContext(NETWORK) {
        Either.catch { service.search(accessToken, options) }.mapLeft { unknown -> unknown.mapNetworkException() }
    }

}
my call to
search
works fine as shown here
Copy code
override suspend fun doActualWork(): Result {

    val work: Either<DatasourceException, *> = either {
        val response = repository.search(options = mapOf("q" to "Nirvana")).bind()
        persistResponse(response).bind()
    }

    return work.fold(ifLeft = { Result.failure() }, ifRight = { Result.success() })
}

private suspend fun persistResponse(response: Response<SearchResponse>): Either<DatasourceException, Long> =
    Either.conditionally(
        isHttpResponseOK(response),
        { manageHTTPError(response).run { NetworkException() } },
        {

            1L
        }
    )
however my call to
searchE
fails with...
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Unable to create converter for retrofit2.Response<com.common.shared.resource.model.network.SearchResponse>
for method DiscogsApi.searchE
and this cause..
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'Response' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
s
I think this should work:
Copy code
suspend fun searchE(accessToken: String = ACCESS_TOKEN, options: Map<String, String>): ResponseE<NetworkException, SearchResponse>