Skip to main content

Errors and Retries

Errors and Retries

Error handling, retry policy, and idempotency guidance for stable integrations.

Audience: Engineers implementing robust clients for Selwise private and public APIs.

Critical: Treat 4xx vs 5xx responses differently: most 4xx are client-actionable, while 5xx and some 429 are retry candidates.

Who This Page Is For

Use this page when implementing retry/backoff behavior, duplicate protection, and error observability for Selwise API calls.

Quick Start (2-5 Minutes)

1

Classify response code

Separate non-retryable client errors from retryable infrastructure errors.

401/403/404/422 usually fix request or permissions; 429/5xx may retry.
2

Honor rate-limit headers

Use Retry-After and X-RateLimit headers for throttled endpoints.

Backoff with jitter; avoid immediate replay loops.
3

Implement idempotency for orders/events

Prevent duplicate purchase/order submissions in retries.

Deduplicate by orderId and client request IDs where possible.
4

Log structured error context

Capture endpoint, payload hash, status, and correlation metadata.

Support fast incident triage and replay decisions.
5

Use bounded retry policy

Set max attempts and escalation threshold.

Example: 3 attempts with exponential backoff and jitter.
6

Handle email webhook idempotency

Provider events may be delivered more than once.

Use providerEventId semantics and treat duplicates as non-fatal.

Required Fields / Minimum Payload

FieldRequiredTypeUsed by eventsDescription
statusCodeRequiredHTTP codeAll API responsesPrimary signal for retry/abort decision.
error/messageConditionalresponse body fieldsError responsesHuman-readable failure reason.
Retry-AfterConditionalheader429 responsesBackoff hint in seconds.
orderIdConditionalstringOrder ingestionKey dedup field for idempotent order submissions.
providerEventIdConditionalstringEmail provider webhook eventsUsed for deduplication in connector-based event ingestion.

Common status handling

200/201  Success
400      Bad request (payload or query issue)
401      Unauthorized (token missing/invalid)
403      Forbidden (permission/site/origin/subscription policy)
404      Not found
409      Conflict (for example duplicate order)
422      Validation error
429      Too many requests (retry with backoff)
500      Internal server error (retry with bounded policy)

# Email delivery specifics
SMTP auth/TLS failure      Mark sender unhealthy and escalate operator action
Permanent recipient reject Suppress recipient and stop replay
Provider duplicate event   Treat as idempotent duplicate, do not retry as error

Event or Endpoint Decision Matrix

ScenarioUse ThisWhy
Receive 400/422Fix payload and do not blind retryClient-side validation issue likely.
Receive 401/403Refresh auth or permissions/origin setupSecurity boundary failure, not transient transport issue.
Receive 409 duplicate orderStop replay and enforce idempotent order flowConflict indicates duplicate submission.
Receive SMTP permanent error (for example 550/5.1.1)Mark as permanent fail + suppress recipientRetrying can damage sender reputation and wastes capacity.
Receive 429Retry with Retry-After + exponential backoffServer explicitly requests paced retry.
Receive 5xxRetry with bounded attempts and alert on persistent failurePotential transient server-side issue.

Common Errors and Fixes

Repeated 429 loops

Cause: Client retries immediately without respecting Retry-After.

Fix: Apply server-provided wait and exponential backoff with jitter.

Duplicate orders in downstream systems

Cause: Retry logic resubmits same order without idempotency keying.

Fix: Deduplicate by orderId and prevent uncontrolled replay.

Persistent 403 on public endpoints

Cause: Origin or subscription validation failure.

Fix: Verify domain/origin and subscription conditions before retrying.

Silent data loss after errors

Cause: No structured error logging and no dead-letter/retry queue.

Fix: Capture structured logs and route failed payloads to retry workflow.

Provider webhook appears to double count events

Cause: Provider retries callback and integration treats duplicate as new.

Fix: Respect providerEventId idempotency and monitor duplicate counters separately from rejected events.

Production Checklist

  • Retry policy differentiates 4xx from 429/5xx responses.Required
  • Retry-After and rate-limit headers are honored.Required
  • SMTP permanent failures trigger suppression and no blind replay.Required
  • Order/event submissions include idempotency safeguards.Required
  • Error telemetry includes endpoint, status, and request context.Required
  • Persistent retry failures trigger operational alerts.Required

Next Steps