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

# Error Handling

> Handle SDK and transaction errors.

This page covers common errors and how to handle them in both SDKs.

***

## Transaction Errors

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> import { Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
>
> try {
>   const tx = new Transaction().add(...instructions);
>   const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
>   console.log("Success:", signature);
> } catch (error) {
>   handleTransactionError(error);
> }
>
> function handleTransactionError(error: any) {
>   const message = error.message || error.toString();
>
>   // Insufficient funds
>   if (message.includes("insufficient funds") || message.includes("0x1")) {
>     console.error("Insufficient USDC or SOL balance");
>     return;
>   }
>
>   // Market closed
>   if (message.includes("MarketClosed") || message.includes("0x1770")) {
>     console.error("Market is closed for trading");
>     return;
>   }
>
>   // Insufficient shares
>   if (message.includes("InsufficientShares") || message.includes("0x1771")) {
>     console.error("Not enough shares to sell");
>     return;
>   }
>
>   // Market not resolved
>   if (message.includes("MarketNotResolved")) {
>     console.error("Market has not been resolved yet");
>     return;
>   }
>
>   // Already voted
>   if (message.includes("AlreadyVoted")) {
>     console.error("You have already voted on this dispute");
>     return;
>   }
>
>   // Transaction timeout
>   if (message.includes("TransactionExpiredBlockheightExceeded")) {
>     console.error("Transaction timed out - please retry");
>     return;
>   }
>
>   // Generic error
>   console.error("Transaction failed:", message);
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> from solana.transaction import Transaction
>
> try:
>     tx = Transaction()
>     tx.add(*instructions)
>     signature = await connection.send_transaction(tx, wallet)
>     print(f"Success: {signature}")
> except Exception as error:
>     handle_transaction_error(error)
>
> def handle_transaction_error(error):
>     message = str(error)
>
>     # Insufficient funds
>     if "insufficient funds" in message or "0x1" in message:
>         print("Insufficient USDC or SOL balance")
>         return
>
>     # Market closed
>     if "MarketClosed" in message or "0x1770" in message:
>         print("Market is closed for trading")
>         return
>
>     # Insufficient shares
>     if "InsufficientShares" in message or "0x1771" in message:
>         print("Not enough shares to sell")
>         return
>
>     # Market not resolved
>     if "MarketNotResolved" in message:
>         print("Market has not been resolved yet")
>         return
>
>     # Already voted
>     if "AlreadyVoted" in message:
>         print("You have already voted on this dispute")
>         return
>
>     # Generic error
>     print(f"Transaction failed: {message}")
> ```

***

## Fetch Errors

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> try {
>   const market = await sdk.orica.fetchMarket(marketAddress);
> } catch (error) {
>   if (error.message.includes("Account does not exist")) {
>     console.error("Market not found");
>   } else {
>     console.error("Failed to fetch market:", error.message);
>   }
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> try:
>     market = await sdk.orica.fetch_market(market_address)
> except Exception as error:
>     if "Account does not exist" in str(error):
>         print("Market not found")
>     else:
>         print(f"Failed to fetch market: {error}")
> ```

***

## Common Error Codes

| Error | Code | Description |
| - | - | - |
| `MarketClosed` | 0x1770 | Trading window has ended |
| `InsufficientShares` | 0x1771 | Not enough shares to sell |
| `MarketNotResolved` | 0x1772 | Cannot redeem before resolution |
| `InvalidOutcome` | 0x1773 | Outcome index out of range |
| `AlreadyVoted` | 0x1774 | User already voted on dispute |
| `DisputeNotActive` | 0x1775 | Dispute is not in voting phase |
| `NoPosition` | 0x1776 | User has no position in market |

***

## RPC Errors

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> try {
>   const markets = await sdk.orica.fetchAllMarkets();
> } catch (error) {
>   if (error.message.includes("429") || error.message.includes("Too Many Requests")) {
>     console.error("Rate limited - wait and retry");
>   } else if (error.message.includes("503") || error.message.includes("Service Unavailable")) {
>     console.error("RPC node unavailable - try a different endpoint");
>   } else if (error.message.includes("timeout")) {
>     console.error("Request timed out - retry");
>   } else {
>     throw error;
>   }
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> try:
>     markets = await sdk.orica.fetch_all_markets()
> except Exception as error:
>     message = str(error)
>     if "429" in message or "Too Many Requests" in message:
>         print("Rate limited - wait and retry")
>     elif "503" in message or "Service Unavailable" in message:
>         print("RPC node unavailable - try a different endpoint")
>     elif "timeout" in message:
>         print("Request timed out - retry")
>     else:
>         raise
> ```

***

## Retry Pattern

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> async function withRetry<T>(
>   fn: () => Promise<T>,
>   maxRetries = 3,
>   delayMs = 1000
> ): Promise<T> {
>   for (let i = 0; i < maxRetries; i++) {
>     try {
>       return await fn();
>     } catch (error) {
>       if (i === maxRetries - 1) throw error;
>
>       const isRetryable = 
>         error.message.includes("timeout") ||
>         error.message.includes("429") ||
>         error.message.includes("503");
>
>       if (!isRetryable) throw error;
>
>       await new Promise(r => setTimeout(r, delayMs * (i + 1)));
>     }
>   }
>   throw new Error("Max retries exceeded");
> }
>
> // Usage
> const markets = await withRetry(() => sdk.orica.fetchAllMarkets());
> ```

> [tab] Python
>
> ```python theme={"dark"}
> import asyncio
>
> async def with_retry(fn, max_retries=3, delay_ms=1000):
>     for i in range(max_retries):
>         try:
>             return await fn()
>         except Exception as error:
>             if i == max_retries - 1:
>                 raise
>
>             message = str(error)
>             is_retryable = (
>                 "timeout" in message or
>                 "429" in message or
>                 "503" in message
>             )
>
>             if not is_retryable:
>                 raise
>
>             await asyncio.sleep(delay_ms * (i + 1) / 1000)
>
>     raise Exception("Max retries exceeded")
>
> # Usage
> markets = await with_retry(sdk.orica.fetch_all_markets)
> ```

***

## Next Steps

> [card] [Best Practices](https://docs.orica.markets/sdk/best-practices.md)
>
> SDK usage patterns.

> [card] [Types](https://docs.orica.markets/sdk/types.md)
>
> Complete type definitions.


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