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

Invalid registration token calling success callback #224

Closed Loubot closed 8 years ago

Loubot commented 8 years ago

I just started using the node-gcm package. Looks great. I'm using "node-gcm": "^0.14.0". I've encountered an issue and google isn't finding the solution for me so apologies if this there's something I'm missing. I'm using sender.send(message, { registrationTokens: registrationTokens }, function (err, response) { if(err) console.error("Error " + JSON.stringify(err)); else console.log("Success " + JSON.stringify(response)); });

with an invalid reg key.

This is returning Success {"multicast_id":-1,"success":0,"failure":1,"canonical_ids":0,"results": [{"error":"NotRegistered"}]}

So it seems that the error is actually firing the success callback. Is this expected behaviour? Do I have to handle the error manually in my success callback? Thanks for help or setting me straight.

eladnava commented 8 years ago

Hi @Loubot, Yes, this is expected behavior -- the GCM API will return success and an array of results with an element for every registration ID you sent. Read more here: https://github.com/ToothlessGear/node-gcm/issues/221#issuecomment-198939053

Loubot commented 8 years ago

Thanks. Makes more sense now after reading that #221