Skip to content

Incorrect example in readme #59

@christophhagen

Description

@christophhagen

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.
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions