Skip to content

Improve 204 (No content) handling and polymorphism #79

Discussion options

You must be logged in to vote

I'd say at this point it is mostly a limitation of Retrofit, I just left this as other people could find themselves in the same situation. I'll leave the solution that works ok below with an expected return of ApiResult<Optional<T>, Throwable> and a specific annotation @OptionalNoContent, although I don't really like it.

internal class NoContentInterceptor : Interceptor {
    private val noContentHttpStatusCodes = arrayOf(204, 205)

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val response = chain.proceed(request)
        
        if (request.getAnnotation<OptionalNoContent>() == null ||
            !response.isSuccessful ||

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
7 replies
@sky-franciscoaleixo
Comment options

@ZacSweers
Comment options

@sky-franciscoaleixo
Comment options

@ZacSweers
Comment options

@sky-franciscoaleixo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ZacSweers
Comment options

@sky-franciscoaleixo
Comment options

Answer selected by sky-franciscoaleixo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
enhancement New feature or request
2 participants
Converted from issue

This discussion was converted from issue #78 on July 29, 2024 16:57.