How to retry requests that were blocked
What is the Automatic Interceptor?
The "Automatic Interceptor" is a feature that allows the SDK to intercept URL requests from your app. Enabling this will reduce the amount of code you will have to write as part of the SDK integration.
URL Requests that were blocked by HUMAN don't reach your server. Therefore, after the user solves the challenge you may want to retry those requests. You can configure the behavior of the SDK when requests are blocked:
-
Delay response until challenge is solved or cancelled - setting this in the policy will delay the error response to your request's handler until the user solves or cancels the challenge. Then, the error you will receive contains the information regarding the challenge result (solved or cancelled).
policy.urlRequestInterceptionType = PXPolicyUrlRequestInterceptionType.INTERCEPT_WITH_DELAYED_RESPONSE
policy.setUrlRequestInterceptionType(PXPolicyUrlRequestInterceptionType.INTERCEPT_WITH_DELAYED_RESPONSE);
-
Intercept and retry request - setting this in the policy will delay the error response to your request's handler until the user solves or cancels the challenge. In addition, when the challenge is solved, the SDK will send the original request one more time. Your request's handler should receive the response from your server without knowing that the request was blocked and sent again. You should note that when the challenge is cancelled or when the second request is also blocked, then the behavior will be the same as the "delay the response until the challenge is solved or cancelled" configuration.
policy.urlRequestInterceptionType = PXPolicyUrlRequestInterceptionType.INTERCEPT_AND_RETRY_REQUEST
policy.setUrlRequestInterceptionType(PXPolicyUrlRequestInterceptionType.INTERCEPT_AND_RETRY_REQUEST);
Disable the request's timeout
You should note that those features are built on top the
OkHttp
's chain mechanism. Therefore, in order to delay the request's response to your handler until the user interacts with the challenge, you must disable the request's timeout in yourHttpClient
. Otherwise, your handler will receive a timeout error and you will not know that your request was blocked nor the challenge was solved/cancelled.
How to disable the request's timeout
Ktor:
private val httpClient: HttpClient = HttpClient(OkHttp) {
install(HttpTimeout) {
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
}
}
OkHttp:
var okHttpClient: OkHttpClient = OkHttpClient.Builder()
.callTimeout(0, TimeUnit.SECONDS)
.build()
OkHttpClient httpClient = new OkHttpClient.Builder()
.callTimeout(0, TimeUnit.SECONDS)
.build();
Updated 12 days ago