> For the complete documentation index, see [llms.txt](https://docs.caf.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.caf.io/caf-sdk/ios/getting-started-with-the-sdk-1/handling-failures.md). Agents can also search and read this documentation through its [MCP server](https://docs.caf.io/~gitbook/mcp).

# Handling Failures

Reference for Certta Liveness delegate events, blocking errors, and failure mapping on iOS, including success handling, diagnostics, and UI guidance.

{% hint style="warning" %}

## This guide covers version 7.0.0 and above. For versions below 7.0.0, please see the [legacy documentation](https://docs.caf.io/caf-sdk/ios/getting-started-with-the-sdk-5.md).

{% endhint %}

When a liveness check fails, the SDK returns a `LivenessFailure` object. For face recognition failures, it contains two strings:

* **`cause`**: a stable snake\_case code that tells you exactly why the process was unsuccessful (for example `face_too_far`).
* **`description`**: a human-readable, localized message describing the same failure.

Understanding and handling the `cause` parameter is critical for providing clear, actionable feedback to your users so they can correct the issue and try again.

***

### Delegate callbacks (`CerttaLivenessDelegate`)

| Delegate      | Meaning                                                                                     |
| ------------- | ------------------------------------------------------------------------------------------- |
| `didFail(_:)` | Business failure: the flow completed, but the outcome was not accepted (`LivenessFailure`). |

***

### Using the `cause` Parameter

The `cause` parameter returns a stable snake\_case code (e.g., `"too_dark"` or `"face_too_far"`). If the reason cannot be classified, `cause` is `"unknown"`.

Best Practice: Do not display these raw codes directly to your end-users. Instead, map the `cause` code to a user-friendly, localized message in your app's UI to guide them on how to fix the problem. Use `description` as a fallback message or for diagnostics, but do not branch your logic on it: its text is localized and can change.

{% hint style="info" %}
`description` is available from **7.8.0**. Before 7.8.0, `faceRecognitionFailure` had only `result` and `cause`, and `cause` held the localized message. Update your `switch` to the three-value pattern shown in the [example below](#example-implementation).
{% endhint %}

#### Available Failure Causes

If the image capture is successful but the face cannot be authenticated or processed, the SDK returns a `faceRecognitionFailure`.

Below is the list of possible `cause` values returned specifically during this phase:

#### Stable `cause` values

| `cause`                                                     | Hint                    |
| ----------------------------------------------------------- | ----------------------- |
| `unknown`                                                   | Unclassified            |
| `too_much_movement`                                         | Excessive head movement |
| `too_bright`, `too_dark`, `lighting_issues`                 | Lighting                |
| `misaligned_face`                                           | Not aligned with guide  |
| `eyes_closed`                                               | Eyes closed             |
| `face_too_far`, `face_too_close`                            | Distance                |
| `sunglasses`, `eyewear`                                     | Glasses                 |
| `obscured_face`                                             | Face covered            |
| `multiple_faces`                                            | More than one face      |
| `face_not_found`                                            | No face in region       |
| `frames_blurry`                                             | Too blurry              |
| `motion_issue`                                              | Motion                  |
| `background_issue`                                          | Background / contrast   |
| `device_issue`, `device_restart`                            | Device                  |
| `system_error`                                              | System                  |
| `rejected`, `timeout`, `user_not_found`, `processing_fault` | Transaction / server    |

***

### Example Implementation

Here is an example of how you might handle a `LivenessFailure`, map the `cause` code to helpful user guidance, and fall back to `description`:

```swift
func mapFailureToUX(_ failure: LivenessFailure) -> (code: String, message: String) {
    switch failure {
    case .imageCaptureFailure(let text):
        return ("image_capture", text)
    case .faceRecognitionFailure(_, let cause, let description):
        let message = localizedHint(forCause: cause) ?? description
        return (cause, message)
    }
}

private func localizedHint(forCause cause: String) -> String? {
    switch cause {
    case "too_dark", "too_bright", "lighting_issues":
        return "Improve lighting and try again."
    case "multiple_faces":
        return "Only one person should be in the camera."
    case "timeout":
        return "Time ran out. Please try again."
    default:
        return nil
    }
}
```

***

### Hybrid bridges (Flutter / React Native)

When the Face Liveness flow runs through the Flutter or React Native bridges, a face recognition failure is delivered as a failed event with these payload keys:

| Key           | Value                                                                            |
| ------------- | -------------------------------------------------------------------------------- |
| `type`        | Always `FaceRecognitionFailure` for this failure class.                          |
| `cause`       | The stable snake\_case code (see [stable `cause` values](#stable-cause-values)). |
| `description` | The human-readable, localized message. Available from 7.8.0.                     |
| `response`    | The signed payload, when available.                                              |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.caf.io/caf-sdk/ios/getting-started-with-the-sdk-1/handling-failures.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
