ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

Better Error Information required #304

Closed Adrian-Sweeney closed 6 years ago

Adrian-Sweeney commented 6 years ago

When sending a pile of notifications if one errors it would be nice to receive more information that the status code. Having the message object and the token that failed returned would allow people to handle the error better.

At present I get 401 but I don't get told which token was the problem

eladnava commented 6 years ago

Hi @Adrian-Sweeney, FCM response code 401 indicates an Authentication Error: https://developers.google.com/cloud-messaging/http-server-ref

It is related to the API key you are sending in the request and not to a specific device token.

I do agree it would be nice to have an explanation along with the HTTP error code though.

Adrian-Sweeney commented 6 years ago

Yes that is correct I was using 401 as an example I only get back the status in that case more information would be helpful for example our system is a whitelabeled system and each customer gets its own server key the sending of notifications is the same code for all clients and the system just sends all notifications that are queued and doesn't care which client ID the notification is for. I would love to get even the payload back as a second or third parameter on the callback so that I could examine it and get the client ID and the notification Id and the User id it was being sent to so that I could flag that there was a problem with one users token and just wipe that token out of the system.

When sending IOS tokens we get the information and wipe the token so that we don't waste time trying to send messages to the same device which will continually fail.

PS thanks for the quick response

eladnava commented 6 years ago

Hi @Adrian-Sweeney, It seems that what you are looking for is detecting and deleting invalid / expired device tokens from your database. Our package already supports this! 👍

Please see this issue for implementation: https://github.com/ToothlessGear/node-gcm/issues/221