# onError()

### Overview

`onError` is a [\<Feathery.Form>](/develop/react/api-guide/form.md) prop and callback function to access and modify form state when an error has occurred in the form.

For example, it's triggered when an integration fails or when the user fills out invalid information. If an error is manually set via the React library, this callback will *not* be triggered. This function can be asynchronous.

### Usage <a href="#usage" id="usage"></a>

You can use `onError` to navigate to a new step, update field values, and more. The function takes a single [Context](#context-api) object that provides form-related state and handlers.

```
import { init, Form } from '@feathery/react';

function App() {
  // Initialize Feathery
  init('SDKKey', 'bob@feathery.io');

  // Show the `aBcDeF` Feathery form
  return <Form
    formId='aBcDeF'
    onError={(context) => {
      context.setStep('Step 4');
    }}
  />
}
```

### Context API

|                   Key                   |                Type                | Description                                     |
| :-------------------------------------: | :--------------------------------: | ----------------------------------------------- |
| [Form Context](/develop/context-api.md) |                                    | Consistently available form state and functions |
|              `errorFieldId`             |              `string`              | The ID of the field that is erroring.           |
|             `errorFieldType`            |            `string enum`           | The type of the field that is erroring.         |
|              `errorMessage`             |              `string`              | The error message.                              |
|                `trigger`                | [triggerData](#triggerdata-object) | The info of the error trigger.                  |

#### `triggerData` Definition <a href="#triggerdata-object" id="triggerdata-object"></a>

|      Key      |      Type     | Description                                                                                                                                     |
| :-----------: | :-----------: | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|      `id`     |    `string`   | The ID of the element that triggered the error.                                                                                                 |
|     `text`    |    `string`   | The text displayed on the element that triggered the error.                                                                                     |
|     `type`    | `string enum` | The type of element that triggered the error. Can be `button`, `text`, or `field`.                                                              |
| `repeatIndex` |   `integer`   | If the element that errored repeats, this specifies which repetition it is. This value is 0-indexed and equals 0 if the element doesn't repeat. |

### Return value

A promise can be optionally returned from this function if it's asynchronous and you want execution to await.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.feathery.io/develop/react/api-guide/form/event-handlers/onerror.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
