Hello, `ResponseException` is not serializable, it...
# ktor
t
Hello,
ResponseException
is not serializable, it throws a
NotSerializableException
. This is because of the
response
field. Can this be changed so it is serializable? https://github.com/ktorio/ktor/blob/178479ba392524d37193fcf2f6b30f570a0a3ba7/ktor-client/ktor-client-core/common/src/io/ktor/client/features/DefaultResponseValidation.kt#L51
e
Hi @Thomas, why do you want serialize the response?
t
Hey @e5l, what I am doing is showing the user an appropriate error message depending on the type of exception. To do this, I serialize the exception so I can pass it to a different Android Fragment using a Bundle. That Android Fragment “converts” the exception to a localised error message.
Maybe I should change it so I first “convert” the exception to a localized message, and put that message in the Bundle instead. However, that would mean I would need to add that to every place in my app where I use Ktor / other possible exceptions. It was way easier to pass the exception to a single place and convert it there.
Do you understand my use case and have suggestions?
e
Ok, I've got it. It looks like we can't mark
HttpResponse
with serializable. Maybe you could write a custom response validator with your own exception(and disable the default)?
t
That could be a solution which is very interesting, thanks. If you look at the source code of Throwable, you can see that it implements Serializable. That is why I assumed that ResponseException would also be serializable. Another popular networking library for Android called Retrofit has something similar. They made the response field transient/nullable. (https://github.com/square/retrofit/blob/master/retrofit/src/main/java/retrofit2/HttpException.java#L30). (also see line 50). Not sure if that is the best way but maybe it gives you some ideas.
e
Actually
transient
is a good idea 🙂 Thanks
t
I am not really sure how transient works in the background, but could that have any effect on closing the response? So that the response does not leak.
e
The response in the exception isn't holding any open resources
👍 1
t
@e5l Do you want me to create a GitHub issue for this?
e
Yep. It’s much easier to track progress together :)
t