Permalink
Browse files

Fix bug where an integer result caused Utils.response to be confused …

…about the version
  • Loading branch information...
tedeh committed Jul 24, 2013
1 parent f9982dd commit c014be1be31eba533099ac588201150ed370d3fc
Showing with 5 additions and 6 deletions.
  1. +4 −2 lib/server.js
  2. +1 −4 lib/utils.js
View
@@ -202,7 +202,8 @@ Server.prototype.call = function(request, originalCallback) {
// special case if empty batch request
if(!request.length) {
- return callback(utils.response(self.error(Server.errors.INVALID_REQUEST)));
+ var error = self.error(Server.errors.INVALID_REQUEST);
+ return callback(utils.response(error, undefined, undefined, self.options.version));
}
return self._batch(request, callback);
}
@@ -316,7 +317,8 @@ Server.prototype._batch = function(requests, callback) {
maybeRespond();
});
} else {
- responses[index] = utils.response(self.error(Server.errors.INVALID_REQUEST));
+ var error = self.error(Server.errors.INVALID_REQUEST);
+ responses[index] = utils.response(error, undefined, undefined, self.options.version);
maybeRespond();
}
};
View
@@ -56,9 +56,6 @@ Utils.request = function(method, params, id, options) {
* @api public
*/
Utils.response = function(error, result, id, version) {
- // allow result and id to be optional arguments
- version = typeof(result) === 'number' ? result : version;
-
id = typeof(id) === 'undefined' || id === null ? null : id;
error = typeof(error) === 'undefined' || error === null ? null : error;
version = typeof(version) === 'undefined' || version === null ? 2 : version;
@@ -252,7 +249,7 @@ Utils.tcpConnectionListenerWrapper = function(server) {
function respondError(err) {
var Server = require('./server');
var error = server.error(Server.errors.PARSE_ERROR, null, String(err));
- var response = Utils.response(error);
+ var response = Utils.response(error, undefined, undefined, self.options.version);
utils.JSON.stringify(response, options, function(err, body) {
if(err) body = ''; // we tried our best.
conn.end(body);

0 comments on commit c014be1

Please sign in to comment.