diff --git a/lib/request.js b/lib/request.js index 4060b5f..2de896c 100644 --- a/lib/request.js +++ b/lib/request.js @@ -28,9 +28,16 @@ var request = function(options, params, callback) { buf.push(data); }); res.on('error', function(err) { + //response error event callback(err); }); }); + + req.on('error', function(err) { + //request error event + callback(err); + }); + if (params) { var stringify; if (options.headers['Content-Type'] && options.headers['Content-Type'].toLowerCase() == 'application/x-www-form-urlencoded') { diff --git a/package.json b/package.json index 8efd434..f302d0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yhsd-api", - "version": "1.0.5", + "version": "1.0.6", "description": "Youhaosuda API SDK for node.", "main": "index.js", "repository": { diff --git a/test/api.test.js b/test/api.test.js index 05f97cb..8f68991 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -106,7 +106,26 @@ describe('test/api.test.js', function () { done(); }) }); - + + it('api should be throw ENOTFOUND error', function (done) { + Yhsd.config.apiHost = 'localhost:32876'; + Yhsd.config.appHost = 'localhost:32876'; + Yhsd.config.httpProtocol = 'http'; + api.get('products',function (err, token) { + if (err){ + // console.log(err.message); + var eResult = err.message.indexOf('ENOTFOUND'); + if (eResult > 0) { + (eResult).should.be.ok(); + done(); + return; + } + } + console.log(token); + done(new Error('没有捕捉到错误!')); + }); + }); + //it('api should be return error code 429', function (done) { // var total = 0; // function _request() {