webmaxru / node-red-contrib-web-push

A Node-RED node for sending Web Push notifications using VAPID
https://www.npmjs.com/package/node-red-contrib-web-push
6 stars 7 forks source link

Improved logging #9

Closed bartbutenaers closed 3 years ago

bartbutenaers commented 3 years ago

Hi @webmaxru,

Our users are struggling to troubleshoot about what is going on in case of a failed notification. I hope that this pull request can improve this problem a bit.

This pull request solves two different issues. But I created a single pull request, since both issues occur in the same catch handler.

Thanks for reviewing!! Bart

1. Handle standard Error objects

When you e.g. change your VAPID keys to an invalid value (e.g. by adding "xxxx" to it), we will catch a standard Error object (i.e. with a stack trace) instead of a WebPushError object:

image

Since such an exception instance has no "failed" property, it will considered as succesfull. So the node status will show "1 send, 0 failed" which is incorrect.

To solve that, I convert the Error exception to a WebPushError:

image

P.S. of course I don't have all the information (statuscode, headers...) that would have been in a normal WebPushError object, but that those extra properties aren't used anyway ...

2. Log the errors in Node-RED

Via node.error I report now the errors to Node-RED, so they appear in the Debug sidebar:

image

That way it is e.g. possible to handle those errors via a Catch-node, and report the problem somehow.

P.S. I remove some fields (headers, ...) to avoid a long cryptic log, with information that is not useful in most cases anyway...