0Bit Documentation

Handle errors and retries

Classify 0Bit API errors, retry only transient failures, and preserve request ids for support.

Good retry behavior prevents duplicate sessions, retry storms, and confusing support cases. Treat validation, authentication, authorization, and state conflicts as terminal until a human or code change fixes the input.

Log request ids, not secrets

Capture response status, error code or class, X-Request-Id, your local attempt id, and the operation name. Redact authorization headers, client secrets, webhook secrets, and customer PII.

Error handling matrix

Status classTypical meaningRetry?Action
400Validation or malformed request.NoFix request construction.
401Missing or malformed credential.NoCheck server configuration.
403Credential, mode, entitlement, or origin rejected.NoFix configuration or approval state.
404Resource missing or not scoped to this credential.NoCheck identifiers and ownership.
409State or idempotency conflict.SometimesRead current state before retrying.
429Rate limited.Yes, with backoffRespect documented retry hints.
5xxTransient server or upstream failure.Yes, boundedRetry with idempotency and jitter.
Network timeoutUnknown result.Yes, boundedRetry the same operation with the same idempotency key.

Retry flow

Bounded retry helper

async function retryApiWrite<T>(operation: () => Promise<T>) {
  for (let attempt = 0; attempt < 4; attempt += 1) {
    try {
      return await operation();
    } catch (error) {
      if (!isRetryable(error) || attempt === 3) throw error;
      await delay(backoffWithJitter(attempt));
    }
  }

  throw new Error('retry_exhausted');
}

On this page