PlatformXeDocs
Get API Key

Error Handling

Circuit breaker, retries, failOpen mode, and timeout handling.

The PlatformXe SDK includes built-in resilience features to handle transient failures gracefully.

Retry with exponential backoff

Transient failures (5xx errors, network timeouts) are automatically retried with exponential backoff and jitter.

const px = new PlatformXeClient({
  apiKey: process.env.PLATFORMXE_API_KEY!,
  retries: 3,      // Up to 3 retry attempts
  timeoutMs: 10000, // 10 second timeout per attempt
});

Retry delays follow this pattern:

AttemptBase delayWith jitter
1200ms150–250ms
2400ms300–500ms
3800ms600–1000ms

Client errors (4xx) are not retried — they indicate invalid requests that will fail again.

failOpen mode

When failOpen is true, the SDK returns an error envelope instead of throwing an exception. This is critical for permission checks where a network failure should not crash your application.

const px = new PlatformXeClient({
  apiKey: process.env.PLATFORMXE_API_KEY!,
  failOpen: true,
});

const result = await px.permissions.check({
  adminId: 'user_xyz789',
  path: 'articles',
  action: 'read',
});

if (!result.success) {
  // PlatformXe unreachable — fall back to default policy
  console.error('Permission check failed:', result.error.message);
  return defaultPolicy(path, action);
}

return result.data.allowed;

Error envelope format

interface ErrorResponse {
  success: false;
  error: {
    code: string;    // e.g., "NETWORK_ERROR", "TIMEOUT", "RATE_LIMITED"
    message: string; // Human-readable description
  };
}

Circuit breaker

The SDK implements a circuit breaker that opens after consecutive failures, preventing cascading timeout delays.

StateBehavior
ClosedRequests flow normally
OpenRequests fail immediately (returns error envelope if failOpen)
Half-openOne probe request sent — if it succeeds, circuit closes

The circuit opens after 5 consecutive failures and resets after 30 seconds.

When the circuit is open and failOpen is false, the SDK throws immediately without making a network request. Always enable failOpen in production for permission checks.

Timeout handling

If a request exceeds timeoutMs, it is aborted. If retries remain, the SDK retries. Otherwise:

  • failOpen: true — returns { success: false, error: { code: 'TIMEOUT' } }
  • failOpen: false — throws a TimeoutError
try {
  const result = await px.permissions.check({
    adminId: 'user_xyz789',
    path: 'articles',
    action: 'read',
  });
} catch (err) {
  if (err.code === 'TIMEOUT') {
    // All retries timed out
    return fallbackDecision();
  }
  throw err;
}

Error codes

CodeDescription
NETWORK_ERRORCould not connect to PlatformXe
TIMEOUTRequest timed out after all retries
RATE_LIMITEDRate limit exceeded (check Retry-After header)
BAD_REQUESTInvalid request parameters
FORBIDDENAPI key missing required scope
NOT_FOUNDResource does not exist
CIRCUIT_OPENCircuit breaker is open