I'm using RxJava with retrofit in a library project. Everything is working fine, I get the expected result when I request data.
@GET(Routes.ME)
fun getUserObservable(): Observable<User>
From the API class:
fun getUser(): Observable<User> {
return usersService.getUserObservable()
}
From the main project which use this library, I get the user like this:
api.getUser().observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe({ user ->
println("Get user success : $user")
}, { error ->
println("Get user error : $error")
})
All is working fine, but if an API error occurs, then the API send us for example:
{reason: "the reason of the error", details: "some details", type:"the type error"}
What I want is to provide explicitly this error to the front which get this error, because until now, when I get the error from the error Observable, the front can't parse this error I want to build. So my purpose is to parse this error from my library, build an Error POJO with the provided API json, and send it when the front get the error. If the error doesn't come from the API, then the front should get the normal error.