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

TypeError: Cannot read property 'error' of undefined failed_tokens example #347

Closed medoix closed 3 years ago

medoix commented 3 years ago

When attempting to filter for the failed tokens after a send using the example in the documentation i keep getting the following

push\server.js:30
      var failed_tokens = gcmdevices.filter((token, i) => response[i].error != null);
                                                                      ^

TypeError: Cannot read property 'error' of undefined
medoix commented 3 years ago
      var failed_tokens = response.results
      .map((res, i) => res.error ? gcmdevices[i] : null)
      .filter(token => token);
      console.log('These tokens are no longer ok:', failed_tokens);