Error Handling

Understanding how to handle errors properly is crucial for building robust applications with the Yuzu402 API.

Error Response Format

All errors follow a consistent JSON structure:

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error description",
    "details": {
      "additionalInfo": "contextual information"
    }
  },
  "timestamp": 1697234567890
}

HTTP Status Codes

Status Code
Meaning
Common Causes

400

Bad Request

Invalid parameters, malformed JSON

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Resource doesn't exist

429

Too Many Requests

Rate limit exceeded

500

Internal Server Error

Server-side issue

503

Service Unavailable

Temporary service disruption

Common Error Codes

Authentication Errors

UNAUTHORIZED

Solution: Verify your API key is correct and included in the Authorization header.

FORBIDDEN

Solution: Upgrade your plan to access this endpoint.

Validation Errors

INVALID_PARAMETERS

Solution: Check the details object for specific parameter issues.

INVALID_PUBLIC_KEY

Solution: Ensure you're providing a valid base58-encoded Solana public key.

INVALID_MINT

Solution: Verify the token mint address is correct and the token exists.

Trading Errors

INSUFFICIENT_BALANCE

Solution: Ensure your wallet has enough SOL to cover the transaction amount plus fees.

SLIPPAGE_EXCEEDED

Solution: Increase slippage tolerance or retry the transaction when market is less volatile.

INSUFFICIENT_LIQUIDITY

Solution: Reduce trade size or wait for liquidity to improve.

Rate Limiting

RATE_LIMIT_EXCEEDED

Solution: Implement exponential backoff and respect the retryAfter value.

Network Errors

NETWORK_ERROR

Solution: Retry the request. If the issue persists, check the status page.

TRANSACTION_FAILED

Solution: Review the logs for specific failure reasons. May require parameter adjustments.

Implementing Error Handling

JavaScript/TypeScript Example

Python Example

Best Practices

  1. Always Check Response Status: Don't assume requests succeeded

  2. Handle Rate Limits Gracefully: Implement exponential backoff

  3. Log Errors: Keep detailed logs for debugging

  4. Retry Transient Errors: Network issues and rate limits are retryable

  5. Don't Retry Non-Retryable Errors: Invalid parameters won't succeed on retry

  6. Monitor Error Rates: High error rates may indicate issues with your integration

  7. Use Timeouts: Don't let requests hang indefinitely

Getting Help

If you encounter persistent errors:

  1. Check the Status Page for system issues

  2. Review your code against the examples

  3. Contact support with error details and request IDs

  4. Follow us on Twitter for updates and community discussions

Last updated