Skip to content

Commit ed20b70

Browse files
committed
Retry wasn't firing error event
1 parent 44c3bc4 commit ed20b70

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

ios/TNMRequestManager.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TNMRequestManager {
5959

6060
// Execute with retry
6161
executeWithRetry(
62+
currentAttempt: 0,
6263
requestId: requestId,
6364
session: session,
6465
url: url,
@@ -88,6 +89,7 @@ class TNMRequestManager {
8889
// MARK: - Private Methods
8990

9091
private func executeWithRetry(
92+
currentAttempt: Int,
9193
requestId: String,
9294
session: URLSession,
9395
url: URL,
@@ -105,6 +107,8 @@ class TNMRequestManager {
105107
request.httpMethod = method
106108
request.httpBody = body
107109

110+
var currentAttemptCounter = currentAttempt
111+
108112
// Add headers
109113
if let headers = headers {
110114
for (key, value) in headers {
@@ -115,13 +119,20 @@ class TNMRequestManager {
115119
TNMLogger.debug("Creating request task", feature: "Request", details: [
116120
"requestId": requestId,
117121
"attempt": attempt,
118-
"hasRetryConfig": retryConfig != nil
122+
"hasRetryConfig": retryConfig != nil,
123+
"currentAttemptCounter": currentAttemptCounter
119124
])
120125

121126
let task = session.dataTask(with: request) { [weak self] data, response, error in
122127
guard let self = self else { return }
123128

124129
if let error = error {
130+
131+
// Notify that we will retry
132+
let willRetryAgain = currentAttemptCounter + 1 < (retryConfig?.maxRetries ?? 0)
133+
currentAttemptCounter = currentAttemptCounter + 1
134+
onError(error, willRetryAgain)
135+
125136
// Check if should retry
126137
if let retryConfig = retryConfig,
127138
attempt < retryConfig.maxRetries,
@@ -140,12 +151,10 @@ class TNMRequestManager {
140151
delay: delay
141152
)
142153

143-
// Notify that we will retry
144-
onError(error, true)
145-
146154
// Retry after delay
147155
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
148156
self.executeWithRetry(
157+
currentAttempt: currentAttemptCounter,
149158
requestId: requestId,
150159
session: session,
151160
url: url,
@@ -170,7 +179,6 @@ class TNMRequestManager {
170179
self.retryState.removeValue(forKey: requestId)
171180

172181
TNMLogger.Request.error(requestId: requestId, error: error)
173-
onError(error, false)
174182
}
175183
return
176184
}
@@ -217,6 +225,7 @@ class TNMRequestManager {
217225

218226
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
219227
self.executeWithRetry(
228+
currentAttempt: currentAttemptCounter,
220229
requestId: requestId,
221230
session: session,
222231
url: url,
-490 KB
Binary file not shown.
491 KB
Binary file not shown.

ios/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# this is your module manifest and used by Titanium
33
# during compilation, packaging, distribution, etc.
44
#
5-
version: 1.0.2
5+
version: 1.0.3
66
apiversion: 2
77
architectures: arm64 x86_64
88
mac: false

0 commit comments

Comments
 (0)