Skip to content

Commit

Permalink
Introduced some better error handling with an exports.error object co…
Browse files Browse the repository at this point in the history
…ntaining error values for message error response code and local errors.
  • Loading branch information
argon committed Oct 8, 2010
1 parent a23f50a commit df55494
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/apn.js
Expand Up @@ -4,6 +4,19 @@ var sys = require('sys');
var fs = require('fs');
var Buffer = require('buffer').Buffer;

var Errors = {
'noErrorsEncountered': 0
, 'processingError': 1
, 'missingDeviceToken': 2
, 'missingTopic': 3
, 'missingPayload': 4
, 'invalidTokenSize': 5
, 'invalidTopicSize': 6
, 'invalidPayloadSize': 7
, 'invalidToken': 8
, 'none': 255
}

var Connection = function (optionArgs) {
this.socket = new net.Stream();
this.credentials = crypto.createCredentials();
Expand Down Expand Up @@ -62,7 +75,12 @@ var Connection = function (optionArgs) {
var messageLength = Buffer.byteLength(message);
var pos = 0;

// Check notification length here. Return non-zero as error
if(token === undefined) {
return Errors['missingDeviceToken'];
}
if(messageLength > 255) {
return Errors['invalidPayloadSize'];
}

note._uid = this.currentId++;

Expand Down Expand Up @@ -344,4 +362,5 @@ function invoke_after(callback) {
exports.connection = Connection;
exports.notification = Notification;
exports.device = Device;
exports.feedback = Feedback;
exports.feedback = Feedback;
exports.error = Errors;

0 comments on commit df55494

Please sign in to comment.