fix(http): Set response.ok
The ok property was not being set on response objects. It's now set based on the status code. Closes #6390 Closes #6503
This commit is contained in:
parent
d4827caa08
commit
92340350d2
|
@ -69,7 +69,8 @@ export class XHRConnection implements Connection {
|
||||||
responseOptions = baseResponseOptions.merge(responseOptions);
|
responseOptions = baseResponseOptions.merge(responseOptions);
|
||||||
}
|
}
|
||||||
let response = new Response(responseOptions);
|
let response = new Response(responseOptions);
|
||||||
if (isSuccess(status)) {
|
response.ok = isSuccess(status);
|
||||||
|
if (response.ok) {
|
||||||
responseObserver.next(response);
|
responseObserver.next(response);
|
||||||
// TODO(gdi2290): defer complete if array buffer until done
|
// TODO(gdi2290): defer complete if array buffer until done
|
||||||
responseObserver.complete();
|
responseObserver.complete();
|
||||||
|
|
|
@ -343,6 +343,34 @@ export function main() {
|
||||||
existingXHRs[0].dispatchEvent('load');
|
existingXHRs[0].dispatchEvent('load');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should set ok to true on 200 return', inject([AsyncTestCompleter], async => {
|
||||||
|
var statusCode = 200;
|
||||||
|
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||||
|
new ResponseOptions({status: statusCode}));
|
||||||
|
|
||||||
|
connection.response.subscribe(res => {
|
||||||
|
expect(res.ok).toBe(true);
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
|
||||||
|
existingXHRs[0].setStatusCode(statusCode);
|
||||||
|
existingXHRs[0].dispatchEvent('load');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set ok to false on 300 return', inject([AsyncTestCompleter], async => {
|
||||||
|
var statusCode = 300;
|
||||||
|
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||||
|
new ResponseOptions({status: statusCode}));
|
||||||
|
|
||||||
|
connection.response.subscribe(res => { throw 'should not be called'; }, errRes => {
|
||||||
|
expect(errRes.ok).toBe(false);
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
|
||||||
|
existingXHRs[0].setStatusCode(statusCode);
|
||||||
|
existingXHRs[0].dispatchEvent('load');
|
||||||
|
}));
|
||||||
|
|
||||||
it('should call error and not complete on 300+ codes',
|
it('should call error and not complete on 300+ codes',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
var nextCalled = false;
|
var nextCalled = false;
|
||||||
|
|
Loading…
Reference in New Issue