Hey, I was wondering how `subscribeScoped` works ...
# mvikotlin
n
Hey, I was wondering how
subscribeScoped
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
Copy code
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?
a
Hello!
subscribeScoped
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:
Copy code
xxx.subscribeScoped(onSuccess = {}, onError = {})
n
@Arkadii Ivanov Oh sorry, and thank you
👍 1