From 67653d2e6c8ce6f7a76bad925980e2d6ddc1330e Mon Sep 17 00:00:00 2001 From: aremes Date: Fri, 8 Apr 2016 16:00:19 +0200 Subject: [PATCH] reject bad http status codes --- index.js | 3 ++- test/mock_adapter_test.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index df4d561..dd1009d 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,8 @@ function adapter() { var response = (handler[1] instanceof Function) ? handler[1](config) : handler.slice(1); - resolve({ + ((response[0] === 1223) || (response[0] >= 200 && response[0] < 300 ) ? resolve : reject) + ({ status: response[0], data: response[1], headers: response[2], diff --git a/test/mock_adapter_test.js b/test/mock_adapter_test.js index 4271f58..9ac3933 100644 --- a/test/mock_adapter_test.js +++ b/test/mock_adapter_test.js @@ -126,6 +126,20 @@ describe('MockAdapter', function() { }); }); + it('rejects when the status is >= 300', function(done) { + mock.onGet('/moo').reply(500); + + instance.get('/moo') + .then( + function(response) { + }, + function(response) { + expect(response.status).to.equal(500); + done(); + } + ); + }); + context('on the default instance', function() { afterEach(function() { axios.defaults.adapter = undefined;