> ## Documentation Index
> Fetch the complete documentation index at: https://developers.paxoslabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> APIError class and error code reference

The SDK provides two error class hierarchies: `APIError` for general SDK errors, and `WithdrawError` for withdrawal-specific failures. Type guard functions are exported for programmatic error handling.

## Import

```ts theme={null}
import {
  APIError,
  VaultNotFoundByAddressError,
  VaultNotFoundByNameError,
  UnauthorizedVaultAccessError,
  isVaultNotFoundByAddressError,
  isVaultNotFoundByNameError,
} from '@paxoslabs/amplify-sdk'
```

## APIError Class

```ts theme={null}
class APIError extends Error {
  /** Human-readable error description */
  message: string

  /** HTTP status code (if applicable) */
  statusCode?: number

  /** SDK function that threw the error (e.g., "prepareDepositAuthorization") */
  endpoint?: string

  /** Original error cause */
  cause?: unknown
}
```

## WithdrawError Hierarchy

Withdrawal operations throw specialized error subclasses with a `code` property for programmatic handling.

```ts theme={null}
class WithdrawError extends Error {
  code: string
  context?: Record<string, unknown>
}
```

### Exported Error Classes

| Class | Code | When Thrown |
| - | - | - |
| `VaultNotFoundByAddressError` | `VAULT_NOT_FOUND_BY_ADDRESS` | Vault address doesn't match any known vault |
| `VaultNotFoundByNameError` | `VAULT_NOT_FOUND_BY_NAME` | Vault name doesn't match any known vault |
| `UnauthorizedVaultAccessError` | `UNAUTHORIZED_VAULT_ACCESS` | API key lacks access to the requested vault |

### Internal Error Subclasses

These are thrown internally but can be caught as `WithdrawError`:

| Code | Description |
| - | - |
| `VAULT_NOT_FOUND` | General vault lookup failure |
| `MULTIPLE_VAULTS_FOUND` | Ambiguous vault filter matched multiple vaults |
| `INVALID_ADDRESS` | Malformed address parameter |
| `INVALID_SHARE_AMOUNT` | Share amount is zero or negative |
| `INVALID_SLIPPAGE` | Slippage outside valid range |
| `INVALID_YIELD_TYPE` | Unrecognized yield type value |
| `INVALID_CHAIN_ID` | Unsupported chain ID |
| `TRANSACTION_DATA_ERROR` | Failed to encode transaction data |
| `VAULT_CACHE_EMPTY` | Vault cache not populated yet |

### Error Type Guards

```ts theme={null}
import {
  isVaultNotFoundByAddressError,
  isVaultNotFoundByNameError,
} from '@paxoslabs/amplify-sdk'

try {
  const txData = await prepareWithdrawOrderTxData(params)
} catch (error) {
  if (isVaultNotFoundByNameError(error)) {
    console.log(error.code) // "VAULT_NOT_FOUND_BY_NAME"
    console.log(error.context) // { vaultName: "..." }
  }

  if (isVaultNotFoundByAddressError(error)) {
    console.log(error.code) // "VAULT_NOT_FOUND_BY_ADDRESS"
    console.log(error.context) // { vaultAddress: "0x..." }
  }
}
```

## Usage

```ts theme={null}
import { APIError, prepareDepositAuthorization } from '@paxoslabs/amplify-sdk'

try {
  const auth = await prepareDepositAuthorization(params)
} catch (error) {
  if (error instanceof APIError) {
    console.log(error.message) // "No vault found for token 0x... with yield type 'CORE' on chain 1"
    console.log(error.endpoint) // "prepareDepositAuthorization"
    console.log(error.statusCode) // 404 (if from an HTTP response)
  }
}
```

## Common Error Scenarios

### Initialization

| Error Message Pattern | Description | Resolution |
| - | - | - |
| `"API key cannot be empty"` | Empty or missing API key | Provide a valid `pxl_...` key |
| `"Invalid API key format"` | Key doesn't meet minimum length | Check key format |
| `"SDK not initialized"` | SDK function called before `initAmplifySDK()` | Call `initAmplifySDK()` at app startup |

### Deposits

| Error Message Pattern | Description | Resolution |
| - | - | - |
| `"No vault found for token..."` | No vault matches yieldType, token, and chainId | Verify parameters with `getSupportedAssets()` |
| `"Token does not support EIP-2612 permit"` | Token lacks permit support | Use approval flow or `forceMethod: "approval"` |
| `"Invalid slippage value"` | Slippage outside 0–10000 bps | Provide value between 0 and 10000 |

### Withdrawals

| Error Message Pattern | Description | Resolution |
| - | - | - |
| `"No vault found for asset..."` | No vault matches parameters | Verify yieldType, wantAsset, and chainId |
| `"WithdrawQueue contract address not configured"` | Vault missing queue address | Contact support — vault may not support withdrawals yet |
| `"Failed to check withdrawal approval"` | On-chain multicall failed | Check RPC connectivity and retry |

## Error Handling Patterns

### Basic Error Handling

```ts theme={null}
try {
  const auth = await prepareDepositAuthorization(params)
} catch (error) {
  if (error instanceof APIError) {
    if (error.message.includes('No vault found')) {
      showError('This token is not supported for the selected yield type')
    } else if (error.message.includes('not initialized')) {
      await initAmplifySDK(apiKey)
    } else {
      showError(error.message)
    }
  }
}
```

### Logging Errors

```ts theme={null}
try {
  const prepared = await prepareDeposit(params)
} catch (error) {
  if (error instanceof APIError) {
    console.error({
      endpoint: error.endpoint,
      statusCode: error.statusCode,
      message: error.message,
    })

    errorTracker.capture(error, {
      extra: {
        endpoint: error.endpoint,
        statusCode: error.statusCode,
      },
    })
  }
}
```

### User-Friendly Messages

```ts theme={null}
function getUserMessage(error: APIError): string {
  if (error.message.includes('not initialized')) {
    return 'Please wait while we connect...'
  }
  if (error.message.includes('No vault found')) {
    return 'This token is not available for the selected strategy.'
  }
  if (error.message.includes('not support EIP-2612')) {
    return 'Please approve the transaction in your wallet.'
  }
  return 'An unexpected error occurred. Please try again.'
}
```

## Related

* [Troubleshooting](https://developers.paxoslabs.com/v0.5.1/intro/products/earn/developers/troubleshooting.md) - Common issues and solutions
* [Logging Guide](https://developers.paxoslabs.com/v0.5.1/intro/products/earn/developers/guides/logging.md) - Debug logging configuration


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.