◈ PulseFlow Cloud / JavaScript SDK
Fictional SDK · local browser demo

Reliability / explicit failure contracts

Retry a transient failure, not a bad assumption.

Use structured codes to decide what to do next. A transport timeout, permission denial and invalid envelope need different operator responses even if they all interrupt telemetry.

Error taxonomy

Code / HTTP statusMeaningAction
AUTH_REQUIRED / 401Missing or invalid credentialsRepair configuration; do not blindly retry
SCOPE_DENIED / 403Workspace or permission mismatchReview the identity's authorization
IDEMPOTENCY_CONFLICT / 409Same key, different bodyInvestigate the caller's key allocation
INVALID_EVENT / 422Envelope failed validationCorrect fields; record a redacted diagnostic
RATE_LIMITED / 429Workspace quota or burst exceededHonor Retry-After and reduce throughput
UNAVAILABLE / 503Temporary service interruptionBounded retry with jitter
TIMEOUT / no responseAcceptance outcome may be unknownRetry only with the same idempotency key
ABORTED / localCaller cancellationStop work; do not retry automatically

A useful error envelope

{
  "error": {
    "code": "INVALID_EVENT",
    "message": "data.duration_ms must be a non-negative integer",
    "request_id": "req_demo_721",
    "retryable": false,
    "details": [{"path": "data.duration_ms", "rule": "integer_min_0"}]
  }
}

Log the code, request ID, workspace ID and field path. Do not log the authorization header or an unrestricted copy of the submitted body. Error messages are for people; machine decisions should use stable codes.

Bound the retry budget

The reference policy allows four total attempts: the original call plus three retries. Use full jitter with a 250 ms base and a 10 second ceiling. On 429 or 503, a valid Retry-After value takes precedence. It may be a delay in seconds or an HTTP date; parse both, reject invalid values and never sleep past the caller's overall deadline.

// Policy sketch; use a tested transport implementation in real code.
const maxAttempts = 4;
const retryIndex = 0; // zero for the first retry
const jitterMs = Math.random() * Math.min(10000, 250 * 2 ** retryIndex);
// Preserve the original event ID, body and idempotency key.
// Stop when maxAttempts or the overall deadline is reached.

A timeout after transmission is ambiguous: the server may already have accepted the event. Generating a new key on each retry defeats idempotency and can create duplicates. Do not retry non-idempotent side effects simply because the client lost its response.

Cancellation and shutdown

Propagate an AbortSignal from the request or worker lifecycle. The imagined SDK should cancel pending sleeps as well as active network operations. During shutdown, stop accepting new telemetry, flush within a bounded deadline, then report any dropped count without blocking process termination forever.

Prevent retry storms

Exercise the failure path

Toggle the timeout switch in the SDK playground. Then use the webhook simulator to compare a 429 receiver with a 500 receiver and replay a duplicate ID. Both demos are local-only and must not be mistaken for a test of real network resilience.

Review token diagnostics when failures are persistent and migration notes when an upgrade changes error behavior.