Skip to content

Error Handling

Response Pattern

Every Sarna API response follows this structure. Check fields in this order:

  1. Errors array — if non-empty, the operation failed
  2. Warnings array — informational; log for operational visibility
  3. HasData — if false, no results found (not an error)
  4. Business data — the actual response payload
{
  "Errors": [],
  "Warnings": [{"Code": "LOW_BALANCE", "Message": "Account balance below $10,000"}],
  "HasData": true,
  "Quote": { "Symbol": "AAPL", "Last": 150.00 }
}

Common Error Codes

HTTP StatusError CodeResolution
401UNAUTHORIZEDCheck Bearer token format and validity
403ADMIN_PERMISSION_REQUIREDRequest admin access from your administrator
400INSUFFICIENT_BUYING_POWERCheck GET /balances/account/id/{id} before ordering
400INVALID_SYMBOLUse POST /search to find valid symbols
429RATE_LIMITEDImplement exponential backoff; check Retry-After header

gRPC Status Code Mapping

gRPC StatusHTTP StatusMeaning
OK (0)200Success
INVALID_ARGUMENT (3)400Bad request parameters
UNAUTHENTICATED (16)401Invalid credentials
PERMISSION_DENIED (7)403Insufficient permissions
NOT_FOUND (5)404Resource not found
RESOURCE_EXHAUSTED (8)429Rate limited
INTERNAL (13)500Server error

Retry Strategy

For transient errors (429, 500, 503):

  1. Wait for Retry-After header value (if present)
  2. Otherwise use exponential backoff: 1s, 2s, 4s, 8s, 16s
  3. Add jitter (random 0-1s) to avoid thundering herd
  4. Max 5 retries, then fail

Do not retry 400, 401, or 403 errors — these require fixing the request.