Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/angular2/src/http/backends/xhr_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class XHRConnection implements Connection {
responseOptions = baseResponseOptions.merge(responseOptions);
}
let response = new Response(responseOptions);
if (isSuccess(status)) {
response.ok = isSuccess(status);
if (response.ok) {
responseObserver.next(response);
// TODO(gdi2290): defer complete if array buffer until done
responseObserver.complete();
Expand Down
29 changes: 29 additions & 0 deletions modules/angular2/test/http/backends/xhr_backend_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ export function main() {
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', inject([AsyncTestCompleter], async => {
var nextCalled = false;
var errorCalled = false;
Expand All @@ -226,6 +254,7 @@ export function main() {
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;
Expand Down