From 02e18fcbb5b41c0b332e6f6c9b0ab13893e5ff52 Mon Sep 17 00:00:00 2001 From: am Date: Thu, 30 Nov 2017 15:20:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E5=85=88?= =?UTF-8?q?=E6=8D=95=E6=8D=89=E4=B8=8D=E5=88=B0=E8=AF=B7=E6=B1=82=E7=AB=AF?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/request.js | 7 +++++++ test/api.test.js | 24 ++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) 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/test/api.test.js b/test/api.test.js index 05f97cb..cafde5b 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -1,6 +1,8 @@ /** * Created by obzerg on 16/1/5. */ +var http = require('http'); +var bluebird = require('bluebird'); var should = require('should'); var Yhsd = require('../index'); @@ -106,7 +108,25 @@ describe('test/api.test.js', function () { done(); }) }); - + + it('api should be return connect ETIMEDOUT 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); + }); + }); + //it('api should be return error code 429', function (done) { // var total = 0; // function _request() { @@ -135,5 +155,5 @@ describe('test/api.test.js', function () { // } // _request(); //}); -}); + }); From 6485e6992474d4910ff37448d8c8a3ed9e8628ce Mon Sep 17 00:00:00 2001 From: am Date: Thu, 30 Nov 2017 15:22:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A5=E4=B8=8A"=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8E=9F=E5=85=88=E6=8D=95=E6=8D=89=E4=B8=8D=E5=88=B0=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=AB=AF=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?"=E7=9A=84=E7=89=88=E6=9C=AC=E5=8F=B7=E6=9B=B4=E6=96=B0;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From ca68009cd23a188affedda9b120bcae46cadf89b Mon Sep 17 00:00:00 2001 From: am Date: Thu, 30 Nov 2017 15:55:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/api.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/api.test.js b/test/api.test.js index cafde5b..8f68991 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -1,8 +1,6 @@ /** * Created by obzerg on 16/1/5. */ -var http = require('http'); -var bluebird = require('bluebird'); var should = require('should'); var Yhsd = require('../index'); @@ -109,7 +107,7 @@ describe('test/api.test.js', function () { }) }); - it('api should be return connect ETIMEDOUT error', 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'; @@ -124,6 +122,7 @@ describe('test/api.test.js', function () { } } console.log(token); + done(new Error('没有捕捉到错误!')); }); }); @@ -155,5 +154,5 @@ describe('test/api.test.js', function () { // } // _request(); //}); - }); +});