Is there an adapter for Retrofit that can generate...
# android
d
Is there an adapter for Retrofit that can generate sealed classes from error codes?
r
You can create a custom TypeAdapter and register it
d
@rkeazor Do you know where I can find decent documentation on how to do so?
r
Sorry I mean Interceptor
g
I don't think that global error handler or interceptor will help for this
To achieve that type adapter is also not enough (type adapter works only with successful response types), you need own CallAdapter.Factory, you can get implementation of existing factory that you use (RxJava, coroutines etc) and modify it to propagate response errors as successful result with some sealed class
đź‘Ť 1
r
i see your point, interceptor will only allow a custom throwable. Your defiantly right @gildor. But keep in mind that means that the return type of that call method would be that Sealed Class. So you would need a success path as well, one that get the actual result… So the sealed class shouldn’t just have child classes for errors
g
Yes, and using CallAdapter you can do this
d
Thanks guys! It's good to know I can achieve this kind of behavior.