Skip to content

Retry policy

SwiftSonic ships an opt-in retry policy with exponential backoff for transient HTTP failures. By default, no retries are attempted — every error reaches your code immediately.

TODO: confirm exact API in 0.6.x. Likely a RetryPolicy type passed via ServerConfiguration. Verify in Sources/SwiftSonic/RetryPolicy.swift (or wherever it lives).

// TODO: replace with verified shape
let retry = RetryPolicy(
maxAttempts: 3,
initialDelay: .milliseconds(200),
multiplier: 2.0
)
let config = ServerConfiguration(
host: "music.example.com",
username: "user",
password: "pass",
retryPolicy: retry
)

Only errors flagged as transient on SwiftSonicError are retried (network timeouts, certain 5xx, transport-level disconnects). Authentication failures, 4xx client errors, and decoding errors are surfaced immediately — retrying would not help.

See Error handling for the full classification.

When a server responds with Retry-After, SwiftSonic honours it via SwiftSonicError.suggestedRetryDelay.

TODO: confirm that the retry policy uses suggestedRetryDelay to override the computed backoff when present.

Omit the retryPolicy parameter (or pass nil/the documented “no retry” value). The default behaviour is no automatic retries.