Parse body before calling back

This commit is contained in:
goferito 2014-09-19 14:30:02 +02:00
parent cf1cf48873
commit 1e2dd873ee

View file

@ -1,7 +1,7 @@
/************************************************************** /*********************************************************
* Simple Node.js module for using the Bing Search API * * Simple Node.js module for using the Bing Search API *
**************************************************************/ *********************************************************/
// Require dependencies // Require dependencies
var request = require('request'), var request = require('request'),
@ -65,7 +65,15 @@ Bing.prototype.search = function(query, callback, options) {
}, },
timeout: opts.reqTimeout timeout: opts.reqTimeout
}, callback); }, function(err, res, body){
// Parse body, if body
body = typeof body === 'string'
? JSON.parse(body)
: body;
callback(err, res, body);
});
}; };
module.exports = Bing; module.exports = Bing;