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 206 forks source link

Improved error handling in extractRecipient() and improved recipient documentation #190

Closed eladnava closed 8 years ago

eladnava commented 8 years ago

Closes #186.

Returns an error to the callback in the following circumstances:

  1. No valid recipient key was provided
  2. A string recipient key (topic, notificationKey) was provided, but was not a string
  3. An array recipient key (registrationIds, registrationTokens) was provided, but was not an array
  4. A valid recipient key was provided but contained false/null/undefined/empty string

In addition:

eladnava commented 8 years ago

@hypesystem fyi

eladnava commented 8 years ago

@hypesystem Fixed, thanks!

hypesystem commented 8 years ago

Very good update :+1: good with some better tests. We could decide to leave the considerations in https://github.com/ToothlessGear/node-gcm/pull/190#commitcomment-15202646 for a later PR, if you wish, but it would also fit in here.

eladnava commented 8 years ago

@hypesystem I agree that we should be checking for multiple recipient keys and erroring out in that case.

I think that we should not be using the Array.prototype.foreach() traversal method in extractRecipient(), because we can't return out of the function easily. Therefore, I have reverted to the good old for(var i in array) and will be pushing the commits in a few.

eladnava commented 8 years ago

@hypesystem Implemented the multiple recipient error logic.

eladnava commented 8 years ago

@hypesystem We good to merge? =)

hypesystem commented 8 years ago

Absolutely :smile: