DocumentationErrors & retries

Errors & retries

v1

Every error has a code, a message, and a request ID. Handle the uncertainty as carefully as the happy path.

A consistent error format

JSON
{
  "error": {
    "code": "validation_error",
    "message": "Choose at least one account."
  },
  "request_id": "req_example"
}

Use the stable code for program logic. The message is intended for diagnosis. Store the request ID with your own logs; do not log bearer keys or connected-account credentials.

HTTPMeaningAction
400Invalid input or unsupported optionCorrect the request using error details
401Missing, invalid, or revoked keyCheck the key and environment
403Insufficient scope or account capabilityGrant the required scope or reconnect the account
404Resource not found in this workspace/modeCheck ID and key environment
409Conflicting state or idempotency payloadInspect the existing post before retrying
429Rate limit reachedWait for Retry-After before retrying
5xxTemporary service or platform failureRetry safe operations with backoff

Idempotency is part of the request

Choose a unique idempotency key for each logical post. Use that same key and the same payload after a timeout. Reusing a key with a different payload is a conflict; use a new key only for a genuinely new post.

TypeScript
try {
  await castrook.posts.create(payload, {
    idempotencyKey: 'campaign-42-post-7',
  });
} catch (error) {
  if (error instanceof CastrookError) {
    console.error(error.code, error.requestId);
  }
}

An uncertain result needs inspection

A platform can accept a write before a network timeout. Castrook does not blindly repeat an ambiguous publish. Inspect the target error and the platform account before creating a replacement. The same caution applies to comment replies, which are not idempotent.

Retry safe operations

The TypeScript client retries GET requests and posts with idempotency keys on transport failures, 429, and 5xx. It respects a bounded Retry-After delay and uses a request timeout. It does not automatically repeat comment replies.

Do not treat HTTP 202, an upload ID, or a platform processing receipt as proof of public publication. Check the final destination state and visibility.