Moonbase Docs
Guides

Error Handling

Understanding API errors and how to handle them

This guide explains how to handle errors from the Moonbase API and use the error codes reference for debugging.

Error Response Format

All API errors return an error object:

{
  "error": {
    "code": "InvalidArgument",
    "message": "E0101_InvalidArgument: The provided input is invalid."
  }
}
FieldDescription
error.codeError code (e.g., InvalidArgument, Unauthenticated, NotFound)
error.messageError reference and description

Error Reference Format

Error messages follow the pattern: E{CODE}_{Reference}: {Description}

Example: E0101_InvalidArgument: The provided input is invalid.

  • E0101 - Numeric error code
  • InvalidArgument - Machine-readable reference
  • The provided input is invalid. - Human-readable message

Error Categories

CategoryDescription
authAuthentication and authorization errors
validationRequest validation failures
tradingOrder and trade execution errors
accountAccount and balance issues
marketMarket data and product errors
rate_limitRate limiting errors
fundingFunding and withdrawal errors
systemInternal system errors

Looking Up Error Codes

Use the Error Codes API to get detailed information about any error:

# Get all error codes
curl https://api.dev.mbhq.net/v1/error-codes

# Filter by category
curl https://api.dev.mbhq.net/v1/error-codes?category=trading

# Look up specific error
curl https://api.dev.mbhq.net/v1/error-codes?ref=E0101_InvalidArgument

Error Code Response

{
  "data": {
    "errors": [
      {
        "ref": "E0101_InvalidArgument",
        "code": "E0101",
        "category": "validation",
        "grpc_code": "InvalidArgument",
        "title": "Invalid Input",
        "message": "The provided input is invalid.",
        "action": "none",
        "severity": "warning",
        "retry_allowed": true,
        "http_status": 400
      }
    ]
  }
}

Response Fields

FieldDescription
refFull error reference identifier
codeShort error code
categoryError classification
grpc_codeCorresponding gRPC code name (e.g., InvalidArgument, Unauthenticated)
titleBrief summary for UI display
messageUser-friendly error description
actionSuggested handling (retry, redirect_login, contact_support, none)
severityLevel indicator (error, warning, info)
retry_allowedWhether the operation can be retried
http_statusCorresponding HTTP status code

Common Errors

Authentication Errors

CodeReferenceCause
E0001AuthRequiredAuthentication required
E0003PermissionDeniedPermission denied for this action
E0004InsufficientScopeAccess token missing required scope

Validation Errors

CodeReferenceCause
E0101InvalidArgumentInvalid input provided
E0104InvalidSymbolTrading symbol is invalid
E0110ValueOutOfRangeValue outside allowed range

Trading Errors

CodeReferenceCause
E0201InsufficientBalanceNot enough balance for operation
E0210OrderLimitExceededMaximum open orders reached
E0213InvalidStopPriceInvalid stop price for order

Funding Errors

CodeReferenceCause
E0601WithdrawalSuspendedWithdrawals temporarily suspended
E0603MinWithdrawalAmountAmount below minimum withdrawal limit
E0605DailyWithdrawalLimitExceededDaily withdrawal limit exceeded

Rate Limit Errors

CodeReferenceCause
E0501RateLimitExceededToo many requests
E0503OrderRateLimitExceededOrder rate limit exceeded

When you receive a rate limit error, check the Retry-After header for when to retry.

Best Practices

  1. Parse error references - Extract the error ref from messages for programmatic handling
  2. Use the error-codes API - Build a local cache of error codes on startup
  3. Check retry_allowed - Only retry operations that support it
  4. Handle action field - Implement flows for redirect_login and contact_support
  5. Log error details - Include the full error ref for debugging

Next Steps