Tower Guidev2
private suspend fun actualWork(): Either<Any, Any> = either { val networkData = repository.pharmaDocumentsSearch(options = mapOf("text" to "*", "limitation.count" to "100")).tapLeft { networkError -> consumeNetworkError(workerName, networkError) }.bind() Either.catch { repository.database.documentSearchItemDAO().insertAsync(manufacture(networkData)) }.tapLeft { databaseError -> consumeDatabaseError(workerName, databaseError) }.bind() }
fun consumeNetworkError(caller: String, exception: CallError) { when (exception) { is HttpError -> doLogging { "$caller Network Http error :: ${exception.code} ${exception.message} ${exception.body}" } is IOError -> doLogging(exception.cause) { "$caller Network IO error" } is UnexpectedCallError -> doLogging(exception.cause) { "$caller Unexpected Network error" } } }
actualWork
override suspend fun pharmaDocumentsSearch(headers: Map<String, String>, options: Map<String, String>): Either<CallError, DocumentsSearch> = withContext(NETWORK) { service.pharmaDocumentsSearch(headers = HEADERS, options) }
Either.catch { }
A modern programming language that makes developers happier.