Skip to content

Commit

Permalink
handle error nandarustam#18
Browse files Browse the repository at this point in the history
  • Loading branch information
ans-4175 committed Oct 26, 2016
1 parent 3d717da commit 2318067
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/fcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@ FCM.prototype.send = function(payload, CB) {
}

function respond() {
var error = null, id = null, parsed_data = null;
var error = null, id = null;

if (data.indexOf('\"multicast_id\":') > -1) {
//handle multicast_id, send by devive token
anyFail = ((JSON.parse(data)).failure > 0);
var anyFail = ((JSON.parse(data)).failure > 0);

if (anyFail) {
error = data.substring(0).trim();
var isResults = ((JSON.parse(data)).results);
if (isResults) {
error = isResults[0].error;
} else {
error = data.substring(0).trim();
}
}

anySuccess = ((JSON.parse(data)).success > 0);
var anySuccess = ((JSON.parse(data)).success > 0);

if (anySuccess) {
id = data.substring(0).trim();
Expand All @@ -96,8 +101,9 @@ FCM.prototype.send = function(payload, CB) {
return;
}

// Success, return message id (without id=)
resolve(id);
// Success, return message id (without id=), or something error happened
if (id) resolve(id);
if (error) reject(error);
}

res.on('data', function(chunk) {
Expand Down

0 comments on commit 2318067

Please sign in to comment.