NNovaNetworkClientSwift networkingGitHub ↗

Intermediate · 15 min

Add bounded resilience

Choose deliberate retry, caching, and typed error boundaries.

You’ll buildA client with bounded retries, freshness rules, and visible failure handling.
1
Step 1

Bound retries

Retries are an explicit product decision. Keep attempts and backoff finite.

Addboundedresilience.swift
var configuration = NetworkClientConfiguration()
configuration.retryPolicy = RetryPolicy(
    maxAttempts: 3,
    baseDelayNanoseconds: 200_000_000,
    maxDelayNanoseconds: 2_000_000_000
)
2
Step 2

Choose cache freshness

Caching serves later calls; coalescing shares only overlapping calls.

Addboundedresilience.swift
configuration.defaultCachePolicy = .cacheFirst(maxAge: 30)
let client = NetworkClient(configuration: configuration)
3
Step 3

Keep failure typed

Switch only on errors that alter product behavior.

Addboundedresilience.swift
do {
    let todo: Todo = try await client.load(request: request, authScope: "public")
    print(todo.title)
} catch NetworkError.cancelled {
    print("Request cancelled")
} catch {
    print(error.localizedDescription)
}
✓

Tutorial complete

A client with bounded retries, freshness rules, and visible failure handling.