Make your `retrofitService.login` return `Observab...
# android
e
Make your
retrofitService.login
return
Observable<LoginSealed.Success>
instead of
Observable<LoginSealed>
d
But that results in typemismatch. Since i am returning
LoginSealed.Failute
in case of
HttpException
or
IOException
e
Add a
.map { it -> it as LoginSealed }
d
Oh nice thanks. But in case of
Success
,
response
is null while there is some response from api.
e
Then maybe the field name is not match
d
Actually fields name are the same. I even tried using
Expose
and
SerializedName
but still response is null.
e
Can you show the api response and your data class in detail?
d
api response
Copy code
{
  "session": "Not available",
  "returnMsg": "Invalid credentials",
  "returnCode": "401"
}
data class
Copy code
data class WSResponse(
        @Expose
        @SerializedName("session")
        val session: String,
        @Expose
        @SerializedName("returnMsg")
        val returnMsg: String,
        @Expose
        @SerializedName("returnCode")
        val returnCode: String
)
e
Then it should be like
data class Success(val session: String, val returnMsg: String, val returnCode: String): LoginSealed()
Your
Success
have a extra wrapping layer so it does not fits the model
d
That means i can't read success data class generic way?
e
How generic do you want? Keep in mind the data class structure needs to match the api response in terms of layer
d
Like this
Copy code
sealed class Result<out T> {
    data class Success<out T>(val data: T) : Result<T>()
    data class Error<out T>(val t: Throwable) : Result<T>()
}
But i think this won't work in my case. Right?
e
Won’t work, you need your api response to be the same structure for it to work i.e.
{"data": { ... } }
Unless you handle in yourself in a custom CallAdapter
d
Oh okay. Thank you sir for the help, really appreciate that.
e
You’re welcome