fix(http): error on non-200 status codes
BREAKING CHANGE: previously http would only error on network errors to match the fetch specification. Now status codes less than 200 and greater than 299 will cause Http's Observable to error. Closes #5130.
This commit is contained in:
@ -99,6 +99,7 @@ export function main() {
|
||||
expect(res.type).toBe(ResponseTypes.Error);
|
||||
async.done();
|
||||
});
|
||||
existingXHRs[0].setStatusCode(200);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
@ -107,7 +108,7 @@ export function main() {
|
||||
new ResponseOptions({type: ResponseTypes.Error}));
|
||||
connection.response.subscribe(res => { expect(res.type).toBe(ResponseTypes.Error); },
|
||||
null, () => { async.done(); });
|
||||
|
||||
existingXHRs[0].setStatusCode(200);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
@ -164,15 +165,57 @@ export function main() {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(res => {
|
||||
expect(res.status).toBe(statusCode);
|
||||
async.done();
|
||||
});
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
|
||||
},
|
||||
errRes => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should call next and complete on 200 codes', inject([AsyncTestCompleter], async => {
|
||||
var nextCalled = false;
|
||||
var errorCalled = false;
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
nextCalled = true;
|
||||
expect(res.status).toBe(statusCode);
|
||||
},
|
||||
errRes => { errorCalled = true; }, () => {
|
||||
expect(nextCalled).toBe(true);
|
||||
expect(errorCalled).toBe(false);
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should call error and not complete on 300+ codes', inject([AsyncTestCompleter], async => {
|
||||
var nextCalled = false;
|
||||
var errorCalled = false;
|
||||
var statusCode = 301;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(res => { nextCalled = true; }, errRes => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
expect(nextCalled).toBe(false);
|
||||
async.done();
|
||||
}, () => { throw 'should not be called'; });
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
it('should normalize IE\'s 1223 status code into 204', inject([AsyncTestCompleter], async => {
|
||||
var statusCode = 1223;
|
||||
var normalizedCode = 204;
|
||||
@ -204,10 +247,11 @@ export function main() {
|
||||
expect(ress.text()).toBe(responseBody);
|
||||
async.done();
|
||||
});
|
||||
existingXHRs[1].setStatusCode(200);
|
||||
existingXHRs[1].setResponse(responseBody);
|
||||
existingXHRs[1].dispatchEvent('load');
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(200);
|
||||
existingXHRs[0].setResponseText(responseBody);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
Reference in New Issue
Block a user