Skip to content

Commit

Permalink
[misc] enable debug support
Browse files Browse the repository at this point in the history
  • Loading branch information
cronopio authored and indexzero committed May 14, 2013
1 parent f2dff5e commit 9b63527
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions node.js/lib/client/client.js
Expand Up @@ -122,6 +122,11 @@ Client.prototype._request = function (options, callback, success) {
options.body = JSON.stringify(options.body);
}

//
// Emit options for debug purpose
//
this.emit('debug::request', options);

//
// Helper function for checking response codes
//
Expand All @@ -133,6 +138,11 @@ Client.prototype._request = function (options, callback, success) {
var statusCode = res.statusCode.toString(),
error;

//
// Emit response for debug purpose
//
self.emit('debug::response', { statusCode: statusCode, result: body });

if (Object.keys(self.failCodes).indexOf(statusCode) !== -1) {
error = new Error('conservatory Error (' + statusCode + '): ' + self.failCodes[statusCode]);
if (body) {
Expand All @@ -158,6 +168,11 @@ Client.prototype._request = function (options, callback, success) {
try { result = JSON.parse(body) }
catch (ex) { }

//
// Emit response for debug purpose
//
self.emit('debug::response', { statusCode: res.statusCode, result: result });

success(res, result);
});
}
Expand Down

0 comments on commit 9b63527

Please sign in to comment.