replace kotlin-result-calladapter with networkresult-calladapter (#2569)
* replace kotlin-result-calladapter with networkresult-calladapter * fix tests
This commit is contained in:
parent
131309e99c
commit
e1c8461423
17 changed files with 53 additions and 62 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue