Handle block responses from the server
v3.0
When the "Automatic Interceptor" is enabled, the SDK will generate an error object when the URL request was blocked or when the challenge was solved/cancelled.You should check the error if it's one of the SDK's errors.
Checking the error
You can check the error by using those APIs:
PerimeterX/isRequestBlockedError(error:)
- returnstrue
when the request was blocked.PerimeterX/isChallengeSolvedError(error:)
- returnstrue
when the request was blocked and the user solved the challenge.PerimeterX/isChallengeCancelledError(error:)
- returnstrue
when the request was blocked and the user cancelled the challenge.
Here is an example on how to check the error:
let dataTask = URLSession.shared.dataTask(with: request) { data, response, error in
if let error {
if PerimeterX.isRequestBlockedError(error: error) {
print("request was blocked by PX")
}
if PerimeterX.isChallengeSolvedError(error: error) {
print("request was blocked by PX and user solved the challenge")
}
if PerimeterX.isChallengeCancelledError(error: error) {
print("request was blocked by PX and challenge was cancelled")
}
}
}
dataTask.resume()
If you are using Alamofire, you should pass the AFError.underlyingError object to those functions
AF.request(url, headers: HTTPHeaders(headers)).response { response in
if let error = response.error?.underlyingError {
// check the error...
}
}
When will you receive those errors
When the "Automatic Interceptor" is enabled, the SDK will handle the block response from your server. The SDK will return the following errors to your URL request's handler:
- "Request was blocked" - The URL request's handler will be called once the block response arrives to your app. A challenge will be presented to the user.
- "Challenge was solved" - The URL request's handler will be called once the challenge was solved by the user. You may retry the URL request after getting this error.
- "Challenge was cancelled" - The URL request'a handler will be called once the challenge was cancelled by the user.
How the SDK presents the block page to the user
When the SDK receives the block response from the server it performs the following actions:
- Presenting a
block view controller
in the app, over your other controllers. - In the
block view controller
the SDK presents a web view which loads the challenge that must be solved by the user (or the bot). - Once the challenge is solved, the SDK removes the
block view controller
and allow the user to continue working in your app.
Updated 12 days ago