diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/service/xhr.js | 2 | ||||
| -rw-r--r-- | test/service/xhrSpec.js | 26 |
3 files changed, 24 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 550fcae2..176a0d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Bug Fixes - Fixed cookies which contained unescaped '=' would not show up in cookie service. +- Consider all 2xx responses as OK, not just 200 diff --git a/src/service/xhr.js b/src/service/xhr.js index 6158b84f..b1b57a82 100644 --- a/src/service/xhr.js +++ b/src/service/xhr.js @@ -85,7 +85,7 @@ angularServiceInject('$xhr', function($browser, $error, $log){ response = fromJson(response, true); } } - if (code == 200) { + if (200 <= code && code < 300) { callback(code, response); } else { $error( diff --git a/test/service/xhrSpec.js b/test/service/xhrSpec.js index fc51eff2..66dbe94d 100644 --- a/test/service/xhrSpec.js +++ b/test/service/xhrSpec.js @@ -2,7 +2,9 @@ describe('$xhr', function() { var scope, $browser, $browserXhr, $log, $xhr, log; beforeEach(function(){ - scope = angular.scope({}, angular.service, { '$log': $log = {} }); + scope = angular.scope({}, angular.service, { '$log': $log = { + error: dump + } }); $browser = scope.$service('$browser'); $browserXhr = $browser.xhr; $xhr = scope.$service('$xhr'); @@ -16,8 +18,7 @@ describe('$xhr', function() { function callback(code, response) { - expect(code).toEqual(200); - log = log + toJson(response) + ';'; + log = log + '{code=' + code + '; response=' + toJson(response) + '}'; } @@ -32,7 +33,24 @@ describe('$xhr', function() { $browserXhr.flush(); - expect(log).toEqual('"third";["second"];"first";'); + expect(log).toEqual( + '{code=200; response="third"}' + + '{code=200; response=["second"]}' + + '{code=200; response="first"}'); + }); + + it('should allow all 2xx requests', function(){ + $browserXhr.expectGET('/req1').respond(200, '1'); + $xhr('GET', '/req1', null, callback); + $browserXhr.flush(); + + $browserXhr.expectGET('/req2').respond(299, '2'); + $xhr('GET', '/req2', null, callback); + $browserXhr.flush(); + + expect(log).toEqual( + '{code=200; response="1"}' + + '{code=299; response="2"}'); }); |
