# extractValidationErrors

> **extractValidationErrors**(`error`): [`FieldErrors`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrors/) \| `null`

Defined in: [react/src/validation.ts:189](https://github.com/B3Pay/ic-reactor/blob/ad82a03d03149c25f0d0f63e453f62e284c28b02/packages/react/src/validation.ts#L189)

Checks if a given error is a ValidationError and optionally
extracts field errors in one step.

## Parameters

### error

`unknown`

## Returns

[`FieldErrors`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrors/) \| `null`

## Example

```tsx
const { mutateAsync } = useActorMutation({ functionName: "transfer" })

const handleSubmit = async (data) => {
  try {
    await mutateAsync([data])
  } catch (error) {
    const fieldErrors = extractValidationErrors(error)
    if (fieldErrors) {
      // Handle validation errors
      Object.entries(fieldErrors).forEach(([field, message]) => {
        form.setError(field, { message })
      })
    } else {
      // Handle other errors
      console.error(error)
    }
  }
}
```