> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# Error handling

Openfort actions resolve expected SDK failures as `{ error }`, so branch on the result instead of wrapping the action in `try/catch`.

## Handle action results

```tsx
import { WalletError } from '@openfort/react'
import { useEthereumEmbeddedWallet } from '@openfort/react/ethereum'

function CreateWallet() {
  const { create } = useEthereumEmbeddedWallet()

  const handleCreate = async () => {
    const result = await create()

    if (result.error) {
      if (result.error instanceof WalletError) {
        console.error(result.error.shortMessage)
      }
      return
    }

    console.log('Created:', result.account.id)
  }

  return <button onClick={handleCreate}>Create wallet</button>
}
```

Use `try/catch` only for other work that can throw, such as your own network requests.

## Error classes

All SDK errors extend `OpenfortError`. Import the specific classes you need and branch with `instanceof`:

```tsx
import {
  AuthenticationError,
  OpenfortConfigError,
  OpenfortError,
  WalletError,
} from '@openfort/react'

function handleError(error: OpenfortError) {
  if (error instanceof AuthenticationError) {
    // Redirect to sign in
  } else if (error instanceof WalletError) {
    // Show a wallet-specific message
  } else if (error instanceof OpenfortConfigError) {
    // Fix the application configuration
  }
}
```

Common exported classes include `NotAuthenticatedError`, `WalletCreationError`, `WalletImportError`, `WalletNotConnectedError`, `RecoveryError`, `ValidationError`, `MissingParameterError`, `ApiRequestError`, and `UnsupportedOperationError`.

## Diagnostic fields

```ts
class OpenfortError extends Error {
  shortMessage: string
  details?: string
  metaMessages?: string[]
  cause?: unknown
  docsPath?: string
  walk(): unknown
}
```

* `shortMessage` is the concise message to show or log.
* `message` combines the short message with available details, documentation, and SDK version context.
* `details` and `metaMessages` provide additional diagnostics.
* `cause` stores the underlying failure.
* `walk()` traverses the cause chain.

## OpenfortHookOptions

Action hooks accept success and error callbacks at hook level and, where supported, per call:

```ts
type OpenfortHookOptions<T> = {
  onSuccess?: (data: T) => void
  onError?: (error: OpenfortError) => void
}
```

```tsx
const { create } = useEthereumEmbeddedWallet()

const result = await create({
  onSuccess: ({ account }) => console.log('Created:', account.id),
  onError: (error) => console.error(error.shortMessage),
})

if (result.error) return
```
