Nikola Milovic
08/13/2021, 10:21 AMsubscribeScoped
works (I am used to the Singles having onError/Success) and how to handle errors in my usecase? I am currently making a request to the backend and it returns the status and data, ktor suspend request so I wrap it in singleFromCoroutine
. Am I supposed to wrap the call in try catch? Eg
return singleFromCoroutine {
try {
val response: HttpResponse =
<http://client.post|client.post>("${serverUrl}${apiEndpoint}/account")
return@singleFromCoroutine CreateAccountResponse(response.status.value)
} catch (e: Exception) {
return@singleFromCoroutine CreateAccountResponse(500, e.message ?: "")
}
I feel like I am seriously missing something here, I can't properly handle errors as I have to have a half-assed response network model that has to hold both the data and the potential error. Or is this the way to go?Arkadii Ivanov
08/13/2021, 10:57 AMsubscribeScoped
comes from Reaktive, it is described in the readme: https://github.com/badoo/Reaktive#subscription-management-with-disposablescope
You should be able to pass onError
callback:
xxx.subscribeScoped(onSuccess = {}, onError = {})
Nikola Milovic
08/13/2021, 11:05 AM