Skip to content

Commit

Permalink
fix(AjaxObservable): 1xx,2xx,3xx requests shouldn't error, only 4xx,5xx
Browse files Browse the repository at this point in the history
w3 rfc2616 defines 4xx,5xx status codes as errors, but anything below is a valid response.
AjaxObservable errors when a request status returns 1xx and 3xx, passing only 2xx requests.

#3308
  • Loading branch information
claudiordgz committed Mar 16, 2018
1 parent dd7c9f1 commit 38faa2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ describe('Observable.ajax', () => {
expect(error.status).to.equal(404);
});

it('should fail on 404', () => {
let error;
it('should succeed on 300', () => {
let result;
let complete = false;
const obj = {
url: '/flibbertyJibbet',
normalizeError: (e: any, xhr: any, type: any) => {
Expand All @@ -273,13 +274,12 @@ describe('Observable.ajax', () => {
method: ''
};

Rx.Observable.ajax(obj).subscribe(x => {
throw 'should not next';
}, (err: any) => {
error = err;
}, () => {
throw 'should not complete';
});
Rx.Observable.ajax(obj)
.subscribe((x: any) => {
result = x;
}, null, () => {
complete = true;
});

expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet');

Expand All @@ -289,9 +289,9 @@ describe('Observable.ajax', () => {
'responseText': 'Wee! I am text!'
});

expect(error instanceof Rx.AjaxError).to.be.true;
expect(error.message).to.equal('ajax error 300');
expect(error.status).to.equal(300);
expect(result.xhr).exist;
expect(result.response).to.deep.equal('Wee! I am text!');
expect(complete).to.be.true;
});

it('should succeed no settings', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/internal/observable/dom/AjaxObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {
status = response ? 200 : 0;
}

if (200 <= status && status < 300) {
// 4xx and 5xx should error (https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
if (status < 400) {
if (progressSubscriber) {
progressSubscriber.complete();
}
Expand Down

0 comments on commit 38faa2e

Please sign in to comment.