I have to deal with a third party api that I canno...
# ktor
a
I have to deal with a third party api that I canno't change, they are using oAuth, however in case the access token is invalid, the Server does not respond with 401 instead with 500 and a custom error code in the response body. How can I rewrite the Response in such a way that the ktor client uses the
refreshTokens
method provided ?
I already tried using
HttpResponseValidator
with
handleResponseExceptionWithRequest
but I can only throw another Exception in there and not sure wich i need to throw to let the client react with refreshTokens.
g
Which plugin are you using?
a
The standard
Auth
plugin :
Copy code
install(Auth) {
    bearer {
        loadTokens {
            ....
        }
        refreshTokens {
             ....
        }
    }
}
a
You can try using this workaround.
a
I already tried that, however i cannot access
body()
in there unfortunatley and i need to parse the responses content json
Copy code
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available)
This is what I get to be perceise. when I do the following:
Copy code
install("CustomAuthError") {
                receivePipeline.intercept(HttpReceivePipeline.Before) { response ->
                    if (response.status == HttpStatusCode.InternalServerError) {
val error = response.body<ErrorContent>()
The Solution otherwise would work I just unfortunately cannot access the content body 😕