From d2c41dc47a37428743da4757ea942d65fd5ae986 Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Tue, 24 Dec 2024 01:29:59 -0800 Subject: [PATCH 1/3] Renamed HTTPError.swift to PushServiceError.swift --- .../WebPush/Errors/{HTTPError.swift => PushServiceError.swift} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sources/WebPush/Errors/{HTTPError.swift => PushServiceError.swift} (100%) diff --git a/Sources/WebPush/Errors/HTTPError.swift b/Sources/WebPush/Errors/PushServiceError.swift similarity index 100% rename from Sources/WebPush/Errors/HTTPError.swift rename to Sources/WebPush/Errors/PushServiceError.swift From 8fef6965a35b0dab11627568ee7f4abfaa5b174e Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Tue, 24 Dec 2024 01:39:26 -0800 Subject: [PATCH 2/3] Renamed HTTPError to PushServiceError Fixes #46 --- Sources/WebPush/Errors/PushServiceError.swift | 10 +++++----- Sources/WebPush/WebPushManager.swift | 2 +- Tests/WebPushTests/ErrorTests.swift | 10 +++++----- Tests/WebPushTests/WebPushManagerTests.swift | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/WebPush/Errors/PushServiceError.swift b/Sources/WebPush/Errors/PushServiceError.swift index 8317fbf..e6b76f8 100644 --- a/Sources/WebPush/Errors/PushServiceError.swift +++ b/Sources/WebPush/Errors/PushServiceError.swift @@ -1,5 +1,5 @@ // -// HTTPError.swift +// PushServiceError.swift // swift-webpush // // Created by Dimitri Bouniol on 2024-12-13. @@ -9,12 +9,12 @@ import AsyncHTTPClient import Foundation -/// An unknown HTTP error was encountered. +/// An unknown Push Service error was encountered. /// /// - SeeAlso: [RFC 8030 Generic Event Delivery Using HTTP Push](https://datatracker.ietf.org/doc/html/rfc8030) /// - SeeAlso: [RFC 8292 Voluntary Application Server Identification (VAPID) for Web Push](https://datatracker.ietf.org/doc/html/rfc8292) /// - SeeAlso: [Sending web push notifications in web apps and browsers — Review responses for push notification errors](https://developer.apple.com/documentation/usernotifications/sending-web-push-notifications-in-web-apps-and-browsers#Review-responses-for-push-notification-errors) -public struct HTTPError: LocalizedError, Sendable { +public struct PushServiceError: LocalizedError, Sendable { /// The HTTP response that was returned from the push service.. public let response: HTTPClientResponse @@ -28,11 +28,11 @@ public struct HTTPError: LocalizedError, Sendable { } public var errorDescription: String? { - "A \(response.status) HTTP error was encountered: \(capturedResponseDescription)." + "A \(response.status) Push Service error was encountered: \(capturedResponseDescription)." } } -extension HTTPError: Hashable { +extension PushServiceError: Hashable { public static func == (lhs: Self, rhs: Self) -> Bool { "\(lhs.capturedResponseDescription)" == "\(rhs.capturedResponseDescription)" } diff --git a/Sources/WebPush/WebPushManager.swift b/Sources/WebPush/WebPushManager.swift index c5cbb02..bb26017 100644 --- a/Sources/WebPush/WebPushManager.swift +++ b/Sources/WebPush/WebPushManager.swift @@ -499,7 +499,7 @@ public actor WebPushManager: Sendable { logger.error("The encrypted payload was too large and was rejected by the push service.") throw MessageTooLargeError() // TODO: 429 too many requests, 500 internal server error, 503 server shutting down - check config and perform a retry after a delay? - default: throw HTTPError(response: response) + default: throw PushServiceError(response: response) } logger.trace("Successfully sent notification") } diff --git a/Tests/WebPushTests/ErrorTests.swift b/Tests/WebPushTests/ErrorTests.swift index 9663a10..8813e5e 100644 --- a/Tests/WebPushTests/ErrorTests.swift +++ b/Tests/WebPushTests/ErrorTests.swift @@ -22,12 +22,12 @@ import Testing #expect("\(Base64URLDecodingError().localizedDescription)" == "The Base64 data could not be decoded.") } - @Test func httpError() { + @Test func pushServiceError() { let response = HTTPClientResponse(status: .notFound) - #expect(HTTPError(response: response) == HTTPError(response: response)) - #expect(HTTPError(response: response).hashValue == HTTPError(response: response).hashValue) - #expect(HTTPError(response: response) != HTTPError(response: HTTPClientResponse(status: .internalServerError))) - #expect("\(HTTPError(response: response).localizedDescription)" == "A 404 Not Found HTTP error was encountered: \(response).") + #expect(PushServiceError(response: response) == PushServiceError(response: response)) + #expect(PushServiceError(response: response).hashValue == PushServiceError(response: response).hashValue) + #expect(PushServiceError(response: response) != PushServiceError(response: HTTPClientResponse(status: .internalServerError))) + #expect("\(PushServiceError(response: response).localizedDescription)" == "A 404 Not Found Push Service error was encountered: \(response).") } @Test func messageTooLargeError() { diff --git a/Tests/WebPushTests/WebPushManagerTests.swift b/Tests/WebPushTests/WebPushManagerTests.swift index 157d771..c428bfb 100644 --- a/Tests/WebPushTests/WebPushManagerTests.swift +++ b/Tests/WebPushTests/WebPushManagerTests.swift @@ -567,7 +567,7 @@ struct WebPushManagerTests { })) ) - await #expect(throws: HTTPError.self) { + await #expect(throws: PushServiceError.self) { try await manager.send(string: "hello", to: .mockedSubscriber()) } } From 93b67250aaf28703d62be4ba0b2ed3abe0cd43b3 Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Tue, 24 Dec 2024 01:39:47 -0800 Subject: [PATCH 3/3] Added a link to swiftinit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 80fd045..7b8703d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ A server-side Swift implementation of the WebPush standard. ## Quick Links - [Documentation](https://swiftpackageindex.com/mochidev/swift-webpush/documentation) +- [Symbol Exploration](https://swiftinit.org/docs/mochidev.swift-webpush) - [Updates on Mastodon](https://mastodon.social/tags/SwiftWebPush) ## Installation