Untitled
unknown
kotlin
a year ago
710 B
8
Indexable
fun <DomainType, ApiDataModel> fetchListAndMap(call: Call<List<ApiDataModel>>, mapper: Mapper<ApiDataModel, DomainType>): Result<List<DomainType>> {
return try {
val apiCallResult = call.execute()
if(!apiCallResult.isSuccessful) {
return Result.Error(exception = Throwable(apiCallResult.message()))
}
if(apiCallResult.body() == null) {
return Result.Error(exception = NoBodyResponseException())
}
val responseData = apiCallResult.body()!!
val mappedResponse = mapper.mapToDomainModelList(responseData)
return Result.Success(mappedResponse)
}catch (ex: Exception) {
Result.Error(ex)
}
}
Editor is loading...
Leave a Comment