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

TypeError: Cannot read property 'error' of undefined #188

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hello. I sent a message and I got a message succesfully. but I have a error code.

The code is below.

TypeError: Cannot read property 'error' of undefined at /var/www/app/push_nodejs/node_modules/node-gcm/lib/sender.js:207:40 at parseAndRespond (/var/www/app/push_nodejs/node_modules/node-gcm/lib/sender.js:26:5) at Request._callback (/var/www/app/push_nodejs/node_modules/node-gcm/lib/sender.js:125:9) at Request.self.callback (/var/www/app/push_nodejs/node_modules/node-gcm/node_modules/request/request.js:198:22) at Request.emit (events.js:98:17) at Request. (/var/www/app/push_nodejs/node_modules/node-gcm/node_modules/request/request.js:1035:10) at Request.emit (events.js:117:20) at IncomingMessage. (/var/www/app/push_nodejs/node_modules/node-gcm/node_modules/request/request.js:962:12) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:944:16

eladnava commented 8 years ago

@intervity Can you please provide the code you used to send the message?

Thanks!

ghost commented 8 years ago

@eladnava

My send code is below.

app.post('/', function(req, res) {
    var regTokens = req.body.device_token;

    var message = {};
    message.title = req.body.title;
    message.sender_type = req.body.sender_type;
    message.sender_name = req.body.sender_name;
    message.sender_profile_image = req.body.sender_profile_image;
    message.content = req.body.message;

    sendData.addData('message', message);

    sender.send(sendData, { registrationTokens: regTokens }, 3, function (err, response) {
        if(err) console.log(err);
        else    console.log(response);
    });

    res.send('ok');
});

and i think i know reason. the registraionTokens is array. but i sent a string. so i have a error code. i did test. I change registraionTokens from string to array. then It's OK.

eladnava commented 8 years ago

@intervity Correct, that would be the reason you're getting this error.

We have an open issue about this and will fix it in the next few days.

ghost commented 8 years ago

@eladnava thank you! It's a very nice module !!