Reputation: 32269
I extended Authenticator
to retrieve the authorization and authentication tokens when I get the authentication challenge (401). It retries 20 times. Is there a way to set a different count (I'd like to set it to 3)?
Just in case it's relevant, I'm using OkHttp(3) with retrofit2.
Upvotes: 4
Views: 2658
Reputation: 10761
I made an extension function for the Response object in Kotlin. Since I'm only interested in trying three times before giving up.
private val Response.reachedMaxAttempts: Boolean
get() = this.priorResponse?.priorResponse?.priorResponse != null
Upvotes: 2
Reputation: 40623
See the Handling Authentication documentation:
private int responseCount(Response response) {
int result = 1;
while ((response = response.priorResponse()) != null) {
result++;
}
return result;
}
Upvotes: 7