Consider all 2xx responses as OK, not just 200

This commit is contained in:
Misko Hevery 2011-03-09 21:12:40 -08:00
parent 26bad2bf87
commit 5343deb3da
3 changed files with 24 additions and 5 deletions

View file

@ -3,6 +3,7 @@
### Bug Fixes ### Bug Fixes
- Fixed cookies which contained unescaped '=' would not show up in cookie service. - Fixed cookies which contained unescaped '=' would not show up in cookie service.
- Consider all 2xx responses as OK, not just 200

View file

@ -85,7 +85,7 @@ angularServiceInject('$xhr', function($browser, $error, $log){
response = fromJson(response, true); response = fromJson(response, true);
} }
} }
if (code == 200) { if (200 <= code && code < 300) {
callback(code, response); callback(code, response);
} else { } else {
$error( $error(

View file

@ -2,7 +2,9 @@ describe('$xhr', function() {
var scope, $browser, $browserXhr, $log, $xhr, log; var scope, $browser, $browserXhr, $log, $xhr, log;
beforeEach(function(){ beforeEach(function(){
scope = angular.scope({}, angular.service, { '$log': $log = {} }); scope = angular.scope({}, angular.service, { '$log': $log = {
error: dump
} });
$browser = scope.$service('$browser'); $browser = scope.$service('$browser');
$browserXhr = $browser.xhr; $browserXhr = $browser.xhr;
$xhr = scope.$service('$xhr'); $xhr = scope.$service('$xhr');
@ -16,8 +18,7 @@ describe('$xhr', function() {
function callback(code, response) { function callback(code, response) {
expect(code).toEqual(200); log = log + '{code=' + code + '; response=' + toJson(response) + '}';
log = log + toJson(response) + ';';
} }
@ -32,7 +33,24 @@ describe('$xhr', function() {
$browserXhr.flush(); $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"}');
}); });