Handle block responses from the server
- 09 Mar 2023
-
Print
-
DarkLight
Handle block responses from the server
- Updated on 09 Mar 2023
-
Print
-
DarkLight
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.
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.
If you are using Alamofire, you should pass the AFError.underlyingError object to those functions. Here is an example:
if let error = response.error?.underlyingError { let isRequestBlockedError = PerimeterX.isRequestBlockedError(error: error) if isRequestBlockedError { print("request was blocked by PX") }}
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.
Was this article helpful?