I want to handle api response using sealed class
sealed class Result<out T> {
data class Success<out T>(val value: T) : Result<T>()
data class Failure<out T>(val throwable: Throwable) : Result<T>()
}
My api is working properly for
@POST("/api/doctor_app/UpdateProfile")
fun UpdateProfile(@Body request: Doctor): Single<GenericResponse>
and when I updated my api to
@POST("/api/doctor_app/UpdateProfile")
fun UpdateProfile(@Body request: Doctor): Single<Result<GenericResponse>>
Failed to invoke private com.utils.Result() with no args
How can I achieve response like
configService.UpdateProfile(doctor)
.subscribeOnIO()
.map {
when(it){
is Result.Success -> Result.Success(it.value)
is Result.Failure -> Result.Failure<GenericResponse>(it.throwable)
}
}
where subscribeOnIO
fun <T> Single<T>.subscribeOnIO(): Single<T> {
return this.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}