zeyneloz / onesignal-node

A Node.js Library for OneSignal push notification service
MIT License
207 stars 48 forks source link

Error on unhandle Promise rejection #28

Closed JeromeBotineau closed 5 years ago

JeromeBotineau commented 5 years ago

Promise are rejected even if callback are pass to onesignal notification. It result to reject a promise which is not handle.

https://github.com/zeyneloz/onesignal-node/blob/32d35f8dae14d052e47b66e766e2b91df1ac06e6/lib/client.js#L37-L40

[DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The problem is developer have to add a callback and catch the error.

// send this notification to All Users except Inactive ones      
myClient.sendNotification(firstNotification, function (err, httpResponse,data) {      
   if (err) {
       console.log('Something went wrong…');
   } else {
       console.log(data, httpResponse.statusCode);
   }
}).catch(() => {
       console.log('Something went wrong…');
});
zeyneloz commented 5 years ago

Thanks for opening this issue. This problem has been fixed in v2.1.1