node-pushnotifications: APN errors not retrieved properly + doc update?

I had a hard time understanding why my iOS push notifications suddenly did not work, and went through multiple issues:

  • The topic property is now REQUIRED since node-apn changed the way to connect to APNs (thanks for the semver breaking BTW…)

  • To find the previous issue, I had to dig in the node-apn code to reveal the error, as node-pushnotifications did not show the error and only shows a successful promise with a failure count and no error message, even though the error message is return from node-apn. It seems that node-apn may have changed the way it returns errors, and the result is that we cannot see the underlying error when a notification sending fails.

It would be nice to fix the doc regarding the topic property and to investigate why error messages are not reported correctly.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 18 (2 by maintainers)

Most upvoted comments

I also just lost quiet some time due to this issue - i temporarily added a console log in the apn module so i could debug better.

Hello @sinedied, @appfeel, @miqmago regarding the topic parameter I created a PR for the README update (https://github.com/appfeel/node-pushnotifications/pull/68) as a follow-up to https://github.com/appfeel/node-pushnotifications/issues/67

Hmm… that’s a little bit messing. Regarding to documentate it in readme.md it’s easy.

Regarding to catch the error, the main purpose of the library was to standarize the response:

            (response.failed || []).forEach((failure) => {
                resumed.failure += 1;
                if (failure.error) {
                    // A transport-level error occurred (e.g. network problem)
                    resumed.message.push({
                        regId: failure.device,
                        error: failure.error,
                    });
                } else {
                    // `failure.status` is the HTTP status code
                    // `failure.response` is the JSON payload
                    resumed.message.push({
                        regId: failure.device,
                        error: new Error(failure.response.reason || failure.response),
                    });
                }
            });

So when there is an error in node-apn the error is directly streamed to the resumed.messages. If there is no failure.error info then a new error is generated with the failure.response info (comming from Apple).

I can’t find where the MissingTopic error is raised. Could you point me to the line in node-apn where this error is generated? Maybe in this way I could try to figure out how to stream the error…

Also would be nice to have the failure object (if you could place a console.log of it) when this error is produced, in order to understand what is comming from node-apn. If the error is not comming, node-pushnotifications is not able to catch it and so it cannot be emmited…