Skip to content

Commit

Permalink
Improve retry example for the Swift SDK (#6895)
Browse files Browse the repository at this point in the history
* More usefully handle errors
* Fixed wrong close tag for snippets
* Move one more import into snippet
  • Loading branch information
shepazon authored Sep 23, 2024
1 parent 1311e5c commit 99126fd
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions swift/example_code/swift-sdk/retry/Sources/entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
// AWS service.

import Foundation
// snippet-start:[retry.swift.imports]
import AWSS3
import SmithyRetries
import SmithyRetriesAPI
// snippet-end:[retry.swift.imports]

@main
struct RetryExample {
Expand All @@ -17,8 +19,8 @@ struct RetryExample {
let config: S3Client.S3ClientConfiguration

// Create an Amazon S3 client configuration object that specifies the
// standard exponential backoff strategy, adaptive retry mode and the
// base maximum number of retries as 5.
// adaptive retry mode and sets the maximum number of attempts to 3.
// If that fails, create a default configuration instead.

do {
// snippet-start:[retry.swift.configure]
Expand All @@ -28,9 +30,13 @@ struct RetryExample {
)
// snippet-end:[retry.swift.configure]
} catch {
print("Error: Unable to create configuration")
dump(error)
exit(1)
do {
config = try await S3Client.S3ClientConfiguration()
} catch {
print("Error: Unable to configure Amazon S3.")
dump(error)
return
}
}

// Create an Amazon S3 client using the configuration created above.
Expand All @@ -52,9 +58,9 @@ struct RetryExample {
print("\(bucket.name ?? "<unknown>")")
}
} catch {
print("Error: Unable to get list of buckets")
print("Error: Unable to get a list of buckets.")
dump(error)
exit(2)
return
}
}
}

0 comments on commit 99126fd

Please sign in to comment.