Skip to content

Error Handling ​

Error Classes ​

HundredXApiError ​

Thrown for API errors returned by the 100x backend.

typescript
import { HundredXApiError } from '100x-sdk';

try {
  await sdk.exchange.placeOrder({ ... });
} catch (error) {
  if (error instanceof HundredXApiError) {
    console.error('API Error:', error.code, error.message);
  }
}

Properties:

PropertyTypeDescription
codestringError code (e.g., "error", "NETWORK_ERROR")
messagestringHuman-readable error message
namestringAlways "HundredXApiError"

AuthenticationError ​

Thrown when trying to use authenticated operations on a read-only SDK instance.

typescript
import { AuthenticationError } from '100x-sdk';

try {
  // This will throw if SDK was created with new HundredX() instead of HundredX.create()
  await sdk.exchange.placeOrder({ ... });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Auth Error:', error.message);
  }
}

Error Format ​

The 100x backend returns errors wrapped in a standard response:

json
{
  "body": null,
  "message": "error description",
  "status": 400
}

The SDK automatically detects errors and throws HundredXApiError.

HTTP Status Codes ​

StatusMeaningCommon Cause
400Bad RequestInvalid order parameters
401UnauthorizedInvalid credentials
403ForbiddenIP not whitelisted, broker ID mismatch
404Not FoundOrder not found
500Internal Server ErrorServer-side issue

Network Errors ​

If the request fails to reach the server:

typescript
try {
  await sdk.info.getOrders();
} catch (error) {
  if (error instanceof HundredXApiError && error.code === 'NETWORK_ERROR') {
    console.error('Server unreachable');
  }
}

Best Practices ​

typescript
import { HundredXApiError, AuthenticationError } from '100x-sdk';

async function placeOrderSafe() {
  try {
    const order = await sdk.exchange.placeOrder({
      marketId: 1,
      isBuy: true,
      amount: '1.0',
      price: '2500.00',
      orderType: 'LIMIT',
    });
    console.log('Order placed:', order.id, order.status);
  } catch (error) {
    if (error instanceof AuthenticationError) {
      console.error('Missing credentials:', error.message);
    } else if (error instanceof HundredXApiError) {
      console.error(`API Error [${error.code}]: ${error.message}`);
    } else {
      throw error;
    }
  }
}

100x Exchange Market Maker SDK