Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IoException: Stream closed #4

Open
zkvarz opened this issue Nov 9, 2017 · 6 comments
Open

IoException: Stream closed #4

zkvarz opened this issue Nov 9, 2017 · 6 comments

Comments

@zkvarz
Copy link

zkvarz commented Nov 9, 2017

There was a toast error message. Sorry, I didn't see anything in logs. Had no time to look into it in details.

@KucherenkoIhor
Copy link
Owner

@zkvarz Hi! I can't reproduce this without any details!

@zkvarz
Copy link
Author

zkvarz commented Nov 9, 2017

I debugged on this. As I understand It cannot parse JSON. I see such stacktrace:

0 = {StackTraceElement@6082} "com.google.gson.Gson.fromJson(Gson.java:825)"
1 = {StackTraceElement@6083} "com.google.gson.Gson.fromJson(Gson.java:775)"
2 = {StackTraceElement@6084} "com.github.kittinunf.fuel.gson.GsonDeserializer.deserialize(FuelGson.kt:16)"
3 = {StackTraceElement@6085} "com.github.kittinunf.fuel.core.ResponseDeserializable$DefaultImpls.deserialize(Deserializable.kt:18)"
4 = {StackTraceElement@6086} "com.github.kittinunf.fuel.gson.GsonDeserializer.deserialize(FuelGson.kt:13)"
5 = {StackTraceElement@6087} "com.github.kittinunf.fuel.core.DeserializableKt.response(Deserializable.kt:85)"
6 = {StackTraceElement@6088} "com.github.kittinunf.fuel.rx.RxFuelKt$rx_result$1.subscribe(RxFuel.kt:31)"

@zkvarz
Copy link
Author

zkvarz commented Nov 9, 2017

It is related to this issue:
kittinunf/fuel#224

@userquin
Copy link

userquin commented Feb 3, 2018

once the response interceptor is removed, a new exception is thrown (ClassCastException): GsonDeserializer cannot convert response from gituhub api to List<Repo>:

(Android Studio 3.0.1: gradle plugin upgraded to 3.0.1)

classcastexception

@userquin
Copy link

userquin commented Feb 3, 2018

object ReposRemoteDataSource : ReposDataSource {

    init {
        FuelManager.instance.basePath = "https://api.github.com"
//        FuelManager.instance.addResponseInterceptor { loggingResponseInterceptor() }
    }

    internal val typeToken = object: TypeToken<Any>() {}
    internal class Deserializer : ResponseDeserializable<List<Repo>> {
        override fun deserialize(reader: Reader): List<Repo>? {
            val result = Gson().fromJson<List<Any>>(reader, typeToken.type)
            return result.filter { it is Map<*,*> }.map {
                it as Map<*,*>
                Repo((it["id"] as? Number)?.toLong(), it["name"] as? String, it["full_name"] as? String, it["description"] as? String, "")
            }
        }
    }

    override fun getRepositories(organization: String): Single<List<Repo>> =
            "/orgs/$organization/repos"
                    .httpGet()
//                    .rx_object(GsonDeserializer<List<Repo>>())
                    .rx_object(Deserializer())
                    .map {
                        it?.component1() ?: throw it?.component2() ?: throw Exception()
                    }
                    .doOnSuccess { it.onEach { it.organization = organization } }

}

@seccomiro
Copy link

@userquin. Can you please explain why?
That looks like a temporary workaround. We'll need to do that to all our new Entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants