Closed Cellule closed 3 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
HTTPError
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
request
It can be a string or a buffer or a stream or an object.
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
basicAuthRequest
json: true
This has lead to many Error: [object Object] in our logs making it very hard to understand why the request failed.
Error: [object Object]
You should update the typings to reflect the type of body in HTTPError and ensure the error message is always a string
body
Thanks for reporting this issue. I merged the fix with this pull request and changes will be released with next version.
According to
HTTPError
, the message/body should be a string https://github.com/zeyneloz/onesignal-node/blob/bd0ae30db2024a4c91e2a726cb51b7671bb9c362/src/errors.ts#L1-L10However, 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-L57It can be a string or a buffer or a stream or an object.
Actually in your case, it is almost always an object (at least for
basicAuthRequest
) because it sendsjson: true
in the config https://github.com/zeyneloz/onesignal-node/blob/bd0ae30db2024a4c91e2a726cb51b7671bb9c362/src/utils.ts#L80-L88This 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
inHTTPError
and ensure the error message is always a string