Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code 302 (Found after redirect) results in UnknownError + No chance to get header and body of the response. #25

Closed
szsoftware opened this issue Dec 2, 2020 · 1 comment · Fixed by #26
Labels
bug Something isn't working

Comments

@szsoftware
Copy link

This is a dependent issue to:
square/okhttp#6456

Workaround: ResonseCodeInterceptor(302, 200)

/**
 * @author szsoftware
 */
class ResponseCodeInterceptor(private val from: Int, private val to: Int) : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val response = chain.proceed(request)
        val headers = response.headers
        val body = response.body

        val newCode = when(val oldCode = response.code) { from -> to else -> oldCode}

        return response
                .newBuilder()
                .code(newCode)
                .headers(headers)
                .body(body)
                .build()
    }
}

In my case I even only needed the headers, since the response body is empty (as expected).
In the responses header, in a Location "field" resides a token which was requested by a previous post request.
Due to sso mechanisms, a ridiculous 303 chain resulted in 302 at the end, what could finally not been processed by Retrofit + NetworkResponseAdapter.

@haroldadmin
Copy link
Owner

Thanks for reporting the issue. This seems like an extension of #23 where information about the response is lost in NetworkResponse.UnknownError. The plan is to add nullable fields to the UnknownError type containing information about the response, such as headers or the raw response itself.

I can not give you an ETA on this, unfortunately. I would be happy to accept external contributions, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants