在retrofit中,如何在不使用Call的情况下,将请求中的Tag作为参数值?

In retrofit, how can I use Tag in the request as a parameter value without using Call?

Retrofit:我想使用Tag注解在请求中传递一些数据,然后我想从拦截器中拦截这些数据。

类似于this

我怎样才能像这样使用它,而不使用 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?>

使用上面的内容让我感到困惑:

java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)

如何将参数中的值作为请求中的标记传递?

顺便说一句:我可以像这样使用标签

@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?>

但我希望它不是注释函数,而是作为此挂起函数中的参数传递。

我使用retrofit @TAG 来传递tag值,在okhttp拦截器中拦截

@GET
suspend fun getUsers(@Tag cacheType: CachePolicy.Type, @Url placeholder: String): Response<UserEntity?>

在我的 Okhttp 拦截器中

override fun intercept(chain: Interceptor.Chain): Response {
        val request =  chain.request() 
        val response = chain.proceed(request)
        request.tag(Invocation::class.java)?.let {
                kotlin.runCatching {
                   val cachePolicyType = it.arguments()[0] as CachePolicy.Type
                } 
        }
        return response
}

如果出现任何错误或 class 转换异常,它也不会在 runCatching 块之外抛出任何异常。