Skip to content

Incorrect example in readme #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
christophhagen opened this issue Feb 8, 2025 · 1 comment
Closed

Incorrect example in readme #59

christophhagen opened this issue Feb 8, 2025 · 1 comment
Assignees

Comments

@christophhagen
Copy link
Contributor

First off: thanks for your work implementing this package!

I'm getting started with web notifications, and trying some examples I discovered that a code example in the readme is incomplete / incorrect:

import WebPush

...

do {
    try await manager.send(
        json: ["title": "Test Notification", "body": "Hello, World!"
        /// If sent from a request, pass the request's logger here to maintain its metadata.
        // logger: request.logger
    )
} catch BadSubscriberError() {
    /// The subscription is no longer valid and should be removed.
} catch MessageTooLargeError() {
    /// The message was too long and should be shortened.
} catch let error as HTTPError {
    /// The push service ran into trouble. error.response may help here.
} catch {
    /// An unknown error occurred.
}

The manager.send() function requires a to: parameter, and the HTTPError type doesn't seem to exist in this repository or any of the dependencies.
I'm also getting errors with the catch statements.

So the code sample could be rewritten to:

import WebPush

...

do {
    try await manager.send(
        json: ["title": "Test Notification", "body": "Hello, World!",
        to: subscriber
        /// If sent from a request, pass the request's logger here to maintain its metadata.
        // logger: request.logger
    )
} catch is BadSubscriberError {
    /// The subscription is no longer valid and should be removed.
} catch is MessageTooLargeError {
    /// The message was too long and should be shortened.
} catch {
    /// An unknown error occurred.
}
@dimitribouniol
Copy link
Member

Good catch! Feel free to open a PR if you want to fix it yourself, otherwise I’ll update it later this weekend ❤️

dimitribouniol added a commit that referenced this issue Feb 8, 2025
dimitribouniol added a commit that referenced this issue Feb 8, 2025
@dimitribouniol dimitribouniol self-assigned this Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants