Skip to content

Commit

Permalink
Fix error details in log
Browse files Browse the repository at this point in the history
  • Loading branch information
paddybyers committed Apr 3, 2015
1 parent 385c472 commit d089038
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion browser/lib/transport/iframeagent.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

var sendRequest = this.sendRequest = XHRRequest.createRequest(sendUri, null, authParams, encodeRequest(items), REQ_SEND);
sendRequest.on('complete', function(err, data) {
if(err) Logger.logAction(Logger.LOG_ERROR, 'IframeAgent.sendItems()', 'on complete: err = ' + err);
if(err) Logger.logAction(Logger.LOG_ERROR, 'IframeAgent.sendItems()', 'on complete: err = ' + Utils.inspectError(err));
self.sendRequest = null;
if(data) self.onData(data);

Expand Down
4 changes: 2 additions & 2 deletions common/lib/client/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var Auth = (function() {
};
tokenRequestCallback(tokenParams, function(err, tokenRequestOrDetails) {
if(err) {
Logger.logAction(Logger.LOG_ERROR, 'Auth.requestToken()', 'token request signing call returned error; err = ' + err);
Logger.logAction(Logger.LOG_ERROR, 'Auth.requestToken()', 'token request signing call returned error; err = ' + Utils.inspectError(err));
if(!('code' in err))
err.code = 40170;
if(!('statusCode' in err))
Expand All @@ -264,7 +264,7 @@ var Auth = (function() {
}
tokenRequest(tokenRequestOrDetails, function(err, tokenResponse, headers, unpacked) {
if(err) {
Logger.logAction(Logger.LOG_ERROR, 'Auth.requestToken()', 'token request API call returned error; err = ' + err);
Logger.logAction(Logger.LOG_ERROR, 'Auth.requestToken()', 'token request API call returned error; err = ' + Utils.inspectError(err));
callback(err);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion common/lib/client/realtimechannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ var RealtimeChannel = (function() {
};

RealtimeChannel.prototype.failPendingMessages = function(err) {
Logger.logAction(Logger.LOG_MINOR, 'RealtimeChannel.failPendingMessages', 'channel; name = ' + this.name + ', err = ' + err);
Logger.logAction(Logger.LOG_MINOR, 'RealtimeChannel.failPendingMessages', 'channel; name = ' + this.name + ', err = ' + Utils.inspectError(err));
for(var i = 0; i < this.pendingEvents.length; i++)
try {
this.pendingEvents[i].callback(err);
Expand Down
4 changes: 2 additions & 2 deletions common/lib/transport/connectionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var ConnectionManager = (function() {
/* first try to establish an http transport */
this.chooseHttpTransport(transportParams, function(err, httpTransport) {
if(err) {
Logger.logAction(Logger.LOG_ERROR, 'ConnectionManager.chooseTransport()', 'Unexpected error establishing transport; err = ' + err);
Logger.logAction(Logger.LOG_ERROR, 'ConnectionManager.chooseTransport()', 'Unexpected error establishing transport; err = ' + Utils.inspectError(err));
/* http failed, or terminal, so nothing's going to work */
callback(err);
return;
Expand Down Expand Up @@ -403,7 +403,7 @@ var ConnectionManager = (function() {
self.ackMessage(serial, count);
});
transport.on('nack', function(serial, count, err) {
Logger.logAction(Logger.LOG_ERROR, 'ConnectionManager on(nack)', 'serial = ' + serial + '; count = ' + count + '; err = ' + err);
Logger.logAction(Logger.LOG_ERROR, 'ConnectionManager on(nack)', 'serial = ' + serial + '; count = ' + count + '; err = ' + Utils.inspectError(err));
if(!err) {
err = new Error('Unknown error');
err.statusCode = 500;
Expand Down
4 changes: 2 additions & 2 deletions common/lib/transport/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ var Transport = (function() {
Transport.prototype.onDisconnect = function(message) {
this.isConnected = false;
var err = message && message.error;
Logger.logAction(Logger.LOG_MINOR, 'Transport.onDisconnect()', 'err = ' + err);
Logger.logAction(Logger.LOG_MINOR, 'Transport.onDisconnect()', 'err = ' + Utils.inspectError(err));
this.emit('disconnected', err);
};

Transport.prototype.onClose = function(message) {
this.isConnected = false;
var err = message && message.error;
Logger.logAction(Logger.LOG_MINOR, 'Transport.onClose()', 'err = ' + err);
Logger.logAction(Logger.LOG_MINOR, 'Transport.onClose()', 'err = ' + Utils.inspectError(err));
this.emit('closed', err);
};

Expand Down
2 changes: 1 addition & 1 deletion common/lib/transport/websockettransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var WebSocketTransport = (function() {
};

WebSocketTransport.prototype.onWsError = function(err) {
Logger.logAction(Logger.LOG_ERROR, 'WebSocketTransport.onError()', 'Unexpected error from WebSocket: ' + err);
Logger.logAction(Logger.LOG_ERROR, 'WebSocketTransport.onError()', 'Unexpected error from WebSocket: ' + Utils.inspectError(err));
this.emit('wserror', err);
/* FIXME: this should not be fatal */
this.abort();
Expand Down
8 changes: 8 additions & 0 deletions common/lib/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,13 @@ var Utils = (function() {
return result;
};

Utils.inspect = function(x) {
return JSON.stringify(x);
};

Utils.inspectError = function(x) {
return (x && x.constructor.name == 'ErrorInfo') ? x.toString() : Utils.inspect(x);
};

return Utils;
})();
2 changes: 1 addition & 1 deletion nodejs/lib/transport/nodecomettransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var NodeCometTransport = (function() {
}

res.on('error', self.onResError = function(err) {
console.log('incomingMessage error: ' + err);
console.log('incomingMessage error: ' + Utils.inspectError(err));
self.complete(err);
});

Expand Down

0 comments on commit d089038

Please sign in to comment.