replace kotlin-result-calladapter with networkresult-calladapter (#2569)

* replace kotlin-result-calladapter with networkresult-calladapter

* fix tests
This commit is contained in:
Konrad Pozniak 2022-05-30 20:03:40 +02:00 committed by GitHub
commit e1c8461423
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 53 additions and 62 deletions

View file

@ -1,23 +0,0 @@
package com.keylesspalace.tusky.util
import retrofit2.Call
import retrofit2.HttpException
/**
* Synchronously executes the call and returns the response encapsulated in a kotlin.Result.
* Since Result is an inline class it is not possible to do this with a Retrofit adapter unfortunately.
* More efficient then calling a suspending method with runBlocking
*/
fun <T> Call<T>.result(): Result<T> {
return try {
val response = execute()
val responseBody = response.body()
if (response.isSuccessful && responseBody != null) {
Result.success(responseBody)
} else {
Result.failure(HttpException(response))
}
} catch (e: Exception) {
Result.failure(e)
}
}