I am sending notification to mobile device for which I have fcm tokens. On sending, I get a response that can for each fcm token have an error. I want to remove the invalid tokens that for sure will no longer work, but keep tokens that may have failed this time and could still work in the future.
I am using the node-gcm
package.
What are the possible values for the error
field in the response of each token.
What checks on this value should I be making to only delete the permanently invalid tokens ?
sender.send(gcmMessage, { registrationTokens: fcmTokens }, (error, response) => {
if (error) {
console.log(error);
} else {
const failedTokens = fcmTokens.filter((_, index) => response.results[index].error != null);
if (failedTokens.length) {
// If there are failed tokens, check these to know whether we should delete them.
this.clearUserFcmTokens(userID, failedTokens);
}
}
});