-
-
Save skydoves/f7db8663112b88efb47c248f136928c1 to your computer and use it in GitHub Desktop.
network_result_call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NetworkResultCall<T : Any>( | |
private val proxy: Call<T> | |
) : Call<NetworkResult<T>> { | |
override fun enqueue(callback: Callback<NetworkResult<T>>) { | |
proxy.enqueue(object : Callback<T> { | |
override fun onResponse(call: Call<T>, response: Response<T>) { | |
val networkResult = handleApi { response } | |
callback.onResponse(this@NetworkResultCall, Response.success(networkResult)) | |
} | |
override fun onFailure(call: Call<T>, t: Throwable) { | |
val networkResult = ApiException<T>(t) | |
callback.onResponse(this@NetworkResultCall, Response.success(networkResult)) | |
} | |
}) | |
} | |
override fun execute(): Response<NetworkResult<T>> = throw NotImplementedError() | |
override fun clone(): Call<NetworkResult<T>> = NetworkResultCall(proxy.clone()) | |
override fun request(): Request = proxy.request() | |
override fun timeout(): Timeout = proxy.timeout() | |
override fun isExecuted(): Boolean = proxy.isExecuted | |
override fun isCanceled(): Boolean = proxy.isCanceled | |
override fun cancel() { proxy.cancel() } | |
} |
How do we handle handleApi suspend method inside onResponse method
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The onResponse method gets an error because the handleApi method is suspend