zeyneloz / onesignal-node

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

Incorrect Error message type #58

Closed Cellule closed 3 years ago

Cellule commented 4 years ago

According to HTTPError, the message/body should be a string https://github.com/zeyneloz/onesignal-node/blob/bd0ae30db2024a4c91e2a726cb51b7671bb9c362/src/errors.ts#L1-L10

However, the body comes from request's reponse which is not definitely a string. https://github.com/zeyneloz/onesignal-node/blob/bd0ae30db2024a4c91e2a726cb51b7671bb9c362/src/utils.ts#L54-L57

It can be a string or a buffer or a stream or an object. image

Actually in your case, it is almost always an object (at least for basicAuthRequest) because it sends json: true in the config https://github.com/zeyneloz/onesignal-node/blob/bd0ae30db2024a4c91e2a726cb51b7671bb9c362/src/utils.ts#L80-L88

This has lead to many Error: [object Object] in our logs making it very hard to understand why the request failed.

You should update the typings to reflect the type of body in HTTPError and ensure the error message is always a string

zeyneloz commented 3 years ago

Thanks for reporting this issue. I merged the fix with this pull request and changes will be released with next version.