Skip to content

Commit 8fef696

Browse files
Renamed HTTPError to PushServiceError
Fixes #46
1 parent d2c41dc commit 8fef696

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Sources/WebPush/Errors/PushServiceError.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// HTTPError.swift
2+
// PushServiceError.swift
33
// swift-webpush
44
//
55
// Created by Dimitri Bouniol on 2024-12-13.
@@ -9,12 +9,12 @@
99
import AsyncHTTPClient
1010
import Foundation
1111

12-
/// An unknown HTTP error was encountered.
12+
/// An unknown Push Service error was encountered.
1313
///
1414
/// - SeeAlso: [RFC 8030 Generic Event Delivery Using HTTP Push](https://datatracker.ietf.org/doc/html/rfc8030)
1515
/// - SeeAlso: [RFC 8292 Voluntary Application Server Identification (VAPID) for Web Push](https://datatracker.ietf.org/doc/html/rfc8292)
1616
/// - 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)
17-
public struct HTTPError: LocalizedError, Sendable {
17+
public struct PushServiceError: LocalizedError, Sendable {
1818
/// The HTTP response that was returned from the push service..
1919
public let response: HTTPClientResponse
2020

@@ -28,11 +28,11 @@ public struct HTTPError: LocalizedError, Sendable {
2828
}
2929

3030
public var errorDescription: String? {
31-
"A \(response.status) HTTP error was encountered: \(capturedResponseDescription)."
31+
"A \(response.status) Push Service error was encountered: \(capturedResponseDescription)."
3232
}
3333
}
3434

35-
extension HTTPError: Hashable {
35+
extension PushServiceError: Hashable {
3636
public static func == (lhs: Self, rhs: Self) -> Bool {
3737
"\(lhs.capturedResponseDescription)" == "\(rhs.capturedResponseDescription)"
3838
}

Sources/WebPush/WebPushManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ public actor WebPushManager: Sendable {
499499
logger.error("The encrypted payload was too large and was rejected by the push service.")
500500
throw MessageTooLargeError()
501501
// TODO: 429 too many requests, 500 internal server error, 503 server shutting down - check config and perform a retry after a delay?
502-
default: throw HTTPError(response: response)
502+
default: throw PushServiceError(response: response)
503503
}
504504
logger.trace("Successfully sent notification")
505505
}

Tests/WebPushTests/ErrorTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import Testing
2222
#expect("\(Base64URLDecodingError().localizedDescription)" == "The Base64 data could not be decoded.")
2323
}
2424

25-
@Test func httpError() {
25+
@Test func pushServiceError() {
2626
let response = HTTPClientResponse(status: .notFound)
27-
#expect(HTTPError(response: response) == HTTPError(response: response))
28-
#expect(HTTPError(response: response).hashValue == HTTPError(response: response).hashValue)
29-
#expect(HTTPError(response: response) != HTTPError(response: HTTPClientResponse(status: .internalServerError)))
30-
#expect("\(HTTPError(response: response).localizedDescription)" == "A 404 Not Found HTTP error was encountered: \(response).")
27+
#expect(PushServiceError(response: response) == PushServiceError(response: response))
28+
#expect(PushServiceError(response: response).hashValue == PushServiceError(response: response).hashValue)
29+
#expect(PushServiceError(response: response) != PushServiceError(response: HTTPClientResponse(status: .internalServerError)))
30+
#expect("\(PushServiceError(response: response).localizedDescription)" == "A 404 Not Found Push Service error was encountered: \(response).")
3131
}
3232

3333
@Test func messageTooLargeError() {

Tests/WebPushTests/WebPushManagerTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ struct WebPushManagerTests {
567567
}))
568568
)
569569

570-
await #expect(throws: HTTPError.self) {
570+
await #expect(throws: PushServiceError.self) {
571571
try await manager.send(string: "hello", to: .mockedSubscriber())
572572
}
573573
}

0 commit comments

Comments
 (0)