Vivek Modi
04/19/2022, 3:08 PMHttpResponseValidator
is used for api status, correct me If I am wrong.
1. I need to call api, if api returns 401 status, I need to call refershToken api. After getting new accessToken from refreshToken api, I need to send this to api call.
2. If refreshToken is giving 401 then I need to infrom my application to logout.
How can I achieve through this Ktor?Vivek Modi
04/19/2022, 3:13 PMactual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(OkHttp) {
config(this)
install(ContentNegotiation) {
json(Json {
prettyPrint = true
ignoreUnknownKeys = true
explicitNulls = false
})
}
engine {
config {
retryOnConnectionFailure(true)
connectTimeout(30, TimeUnit.SECONDS)
readTimeout(40, TimeUnit.SECONDS)
}
}
defaultRequest {
header("Client-Version", Platform().versionCode)
}
HttpResponseValidator {
validateResponse { response ->
when (response.status.value) {
401 -> {
}
}
}
}
install(Auth) {
bearer {
loadTokens {
BearerTokens(tokenProvider.accessToken, "")
}
}
}
}
Vivek Modi
04/19/2022, 3:13 PMexpect fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient