Retrofit: I want to use Tag annotation to pass some data in the request, and then I would like to intercept that data from the interceptor.
Something like this
How can I use it something like this, but without using Call
@Target(AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.FUNCTION
)
@Retention(AnnotationRetention.RUNTIME)
annotation class Tagz
@GET
suspend fun getUsers(@Tagz value: CachePolicy.Type, @Url placeholder: String): Response<UserEntity?>
Using the above is throwing me this:
java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
How can I pass my value in the parameter as a tag in the request?
BTW: I was able to use tag like this
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@Retention(AnnotationRetention.RUNTIME)
annotation class CachePolicyTag(val value: CachePolicy.Type)
@GET
@CachePolicyTag(CachePolicy.Type.DefaultCache)
suspend fun getUsers(@Url placeholder: String): Response<UserEntity?>
But instead of an annotation function, I want it to pass as a parameter in this suspend function.
I used retrofit @TAG to pass tag value and intercepted in the okhttp interceptor.
and in my Okhttp interceptor
In case of any errors or class cast exception, it won't throw any exception out side of the runCatching block as well.