Skip to content

Commit 5a71e4e

Browse files
committed
Refactor RetryModifierTests for improved clarity and functionality
- Updated retry tests to use async/await syntax for better readability. - Enhanced retry limit tests to cover default and nil conditions. - Added tests for exponential backoff and dynamic retry intervals. - Improved retry condition tests to include safe method checks and status code conditions. - Refactored test methods to ensure consistent naming and structure. - Updated TestHTTPClient to support async testing, ensuring compatibility with new async test methods.
1 parent 4a6fb5e commit 5a71e4e

File tree

6 files changed

+805
-212
lines changed

6 files changed

+805
-212
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Custom callers can be created for different types of requests, such as WebSocket
161161
The `.decodable` serializer uses the `.bodyDecoder` configuration, which can be customized with the `.bodyDecoder` modifier. The default `bodyDecoder` is `JSONDecoder()`.
162162

163163
#### Some execution modifiers
164-
- `.retry(limit:)` for retrying a request a specified number of times.
164+
- `.retry()` for retrying requests with configurable conditions, limits, intervals, and automatic `Retry-After` header support.
165165
- `.throttle(interval:)` for throttling requests with a specified interval.
166166
- `.timeout(_:)` for setting an execution timeout.
167167
- `.waitForConnection()` for waiting for a connection before executing a request.

Sources/SwiftAPIClient/APIClientConfigs.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ public extension APIClient {
1818
/// - Parameter keyPath: A `WritableKeyPath` to the configuration property.
1919
/// - Returns: The value of the configuration property if it exists, or `nil` otherwise.
2020
public subscript<T>(_ keyPath: WritableKeyPath<APIClient.Configs, T>) -> T? {
21-
get { values[keyPath] as? T }
22-
set { values[keyPath] = newValue }
23-
}
24-
25-
/// Provides subscript access to configuration values based on their key paths.
26-
/// - Parameter keyPath: A `WritableKeyPath` to the configuration property.
27-
/// - Returns: The value of the configuration property if it exists, or `nil` otherwise.
28-
public subscript<T>(_ keyPath: WritableKeyPath<APIClient.Configs, T?>) -> T? {
29-
get { values[keyPath] as? T }
30-
set { values[keyPath] = newValue }
21+
get {
22+
if let value = values[keyPath] {
23+
return value as? T
24+
}
25+
return nil
26+
}
27+
set {
28+
if let newValue {
29+
values[keyPath] = newValue
30+
} else {
31+
values.removeValue(forKey: keyPath)
32+
}
33+
}
3134
}
3235

3336
/// Returns a new `Configs` instance with a modified configuration value.

Sources/SwiftAPIClient/Modifiers/CodeLocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public extension APIClient.Configs {
2525

2626
/// The code location of the call site.
2727
var codeLocation: CodeLocation? {
28-
get { self[\.codeLocation] }
28+
get { self[\.codeLocation] ?? nil }
2929
set { self[\.codeLocation] = newValue }
3030
}
3131
}

0 commit comments

Comments
 (0)