From b5ff96bb34f0762cae348efa2ae9037ee451f7c9 Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Wed, 19 Jul 2023 08:48:57 +0200 Subject: [PATCH] Add RetryLogging.onError --- Sources/Retry/Retry.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Retry/Retry.swift b/Sources/Retry/Retry.swift index d5f57f3..a27d73a 100644 --- a/Sources/Retry/Retry.swift +++ b/Sources/Retry/Retry.swift @@ -39,6 +39,7 @@ public enum Retry { do { return try block() } catch { + logger.onError(label: label, error: error) lastError = "\(error)" guard retriesLeft > 0 else { break } let delay = backedOffDelay(baseDelay: delay, attempt: currentTry) @@ -56,6 +57,7 @@ public enum Retry { public protocol RetryLogging { func onStartOfRetry(label: String, attempt: Int) func onStartOfDelay(label: String, delay: Double) + func onError(label: String, error: Error) } @@ -69,6 +71,10 @@ public struct DefaultLogger: RetryLogging { public func onStartOfDelay(label: String, delay: Double) { print("Retrying in \(delay) seconds ...") } + + public func onError(label: String, error: Error) { + print(error) + } }