Skip to content

Commit 9817c2e

Browse files
authored
Merge pull request #9 from bartbutenaers/log-notification-errors
Improved logging
2 parents d46e7d7 + 34ca4fb commit 9817c2e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

web-push.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ module.exports = function (RED) {
4141
}
4242
})
4343
}).catch((err) => {
44+
// When a standard error text has been received, make sure it is converted to mimic a WebPushError object.
45+
// Otherwise it has no 'failed' property, so it will be considered no failure further on ...
46+
if (err instanceof Error) {
47+
err = {
48+
failed: {
49+
name: err.name,
50+
message: "Standard exception",
51+
body: err.message
52+
}
53+
}
54+
}
55+
56+
// Remove some properties from the WebPushError to make sure the logs only contain useful information
57+
delete err.failed.headers
58+
delete err.failed.endpoint
59+
60+
// Log the error message to simplify troubleshooting
61+
node.error(JSON.stringify(err.failed))
62+
4463
resolve({
4564
failed: JSON.parse(JSON.stringify(err))
4665
})

0 commit comments

Comments
 (0)