From c23fc23049e9ac7f9450b2b41c16f39785e026b4 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Mon, 19 Aug 2024 20:59:10 -0400 Subject: [PATCH] added `RequestStatus` enum --- Sources/KlaviyoSwift/SDKRequestIterator.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/KlaviyoSwift/SDKRequestIterator.swift b/Sources/KlaviyoSwift/SDKRequestIterator.swift index 2e430e84..8294202a 100644 --- a/Sources/KlaviyoSwift/SDKRequestIterator.swift +++ b/Sources/KlaviyoSwift/SDKRequestIterator.swift @@ -128,6 +128,23 @@ public struct SDKRequest: Identifiable, Equatable { } } +@_spi(KlaviyoPrivate) +public enum RequestStatus { + public enum RequestError: Error { + case requestFailed(Error) + /// The server responded with a 429 HTTP status code, indicating that the client is being rate-limited. + /// - Parameter retryAfter: The amount of time, in seconds, that the client should wait before making another request. + case rateLimited(retryAfter: Int) + /// - Parameter duration: The elapsed time, in seconds, between the API call and the server’s response. + case httpError(statusCode: Int, duration: TimeInterval) + } + + case started + /// - Parameter duration: The elapsed time, in seconds, between the API call and the server’s response. + case completed(data: Data, duration: TimeInterval) + case error(RequestError) +} + @_spi(KlaviyoPrivate) public func requestIterator() -> AsyncStream { AsyncStream { continuation in