You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// When the rate limit is exceeded, the request will be repeated after the specified interval and all requests with the same base URL will be suspended.
22
24
/// - Parameters:
23
25
/// - interval: The interval to wait before repeating the request. Default to 30 seconds.
24
26
/// - statusCodes: The set of status codes that indicate a rate limit exceeded. Default to `[429]`.
27
+
/// - methods: The set of HTTP methods to retry. If `nil`, all methods are retried. Default to `nil`.
25
28
/// - maxRepeatCount: The maximum number of times the request can be repeated. Default to 3.
Copy file name to clipboardExpand all lines: Sources/SwiftAPIClient/Modifiers/RetryModifier.swift
+109-6Lines changed: 109 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -5,31 +5,134 @@ import FoundationNetworking
5
5
import HTTPTypes
6
6
7
7
publicextensionAPIClient{
8
-
8
+
9
+
/// Retries the request if it fails.
10
+
/// - Parameters:
11
+
/// - limit: The maximum number of retries. If `nil`, it will retry indefinitely.
12
+
/// - interval: The time interval to wait before the next retry. If not provided.
13
+
/// - condition: A closure that takes the request, the result of the request, and the client configs, and returns a Boolean indicating whether to retry the request. If not provided, it defaults to retrying safe methods (like GET) on error status codes or network errors.
14
+
/// - Note: Like any modifier, this is order dependent. It takes in account only error from previous modifiers but not the following ones.
15
+
func retry(
16
+
when condition:RetryRequestCondition=.requestFailed,
17
+
limit:Int?,
18
+
interval:TimeInterval
19
+
)->APIClient{
20
+
retry(when: condition,limit: limit, interval:{ _ in interval })
/// - limit: The maximum number of retries. If `nil`, it will retry indefinitely.
26
+
/// - interval: A closure that takes the current retry count (starting from 0) and returns the time interval to wait before the next retry. If not provided, it defaults to 0 seconds.
27
+
/// - condition: A closure that takes the request, the result of the request, and the client configs, and returns a Boolean indicating whether to retry the request. If not provided, it defaults to retrying safe methods (like GET) on error status codes or network errors.
28
+
/// - Note: Like any modifier, this is order dependent. It takes in account only error from previous modifiers but not the following ones.
29
+
func retry(
30
+
when condition:RetryRequestCondition=.requestFailed,
/// Initializes a new `RetryRequestCondition` with a custom condition closure.
44
+
/// - Parameters:
45
+
/// - condition: A closure that takes the request, the result of the request, and the client configs, and returns a Boolean indicating whether to retry the request.
0 commit comments