Skip to content

Commit b5ff96b

Browse files
committed
Add RetryLogging.onError
1 parent 6cb6161 commit b5ff96b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/Retry/Retry.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public enum Retry {
3939
do {
4040
return try block()
4141
} catch {
42+
logger.onError(label: label, error: error)
4243
lastError = "\(error)"
4344
guard retriesLeft > 0 else { break }
4445
let delay = backedOffDelay(baseDelay: delay, attempt: currentTry)
@@ -56,6 +57,7 @@ public enum Retry {
5657
public protocol RetryLogging {
5758
func onStartOfRetry(label: String, attempt: Int)
5859
func onStartOfDelay(label: String, delay: Double)
60+
func onError(label: String, error: Error)
5961
}
6062

6163

@@ -69,6 +71,10 @@ public struct DefaultLogger: RetryLogging {
6971
public func onStartOfDelay(label: String, delay: Double) {
7072
print("Retrying in \(delay) seconds ...")
7173
}
74+
75+
public func onError(label: String, error: Error) {
76+
print(error)
77+
}
7278
}
7379

7480

0 commit comments

Comments
 (0)