fix(http) : set response.ok based on given status code

Closes #8056
This commit is contained in:
simon-ramsay 2016-04-13 19:07:20 -04:00 committed by Simon Ramsay
parent 45f5df371d
commit 30c43521d3
2 changed files with 25 additions and 0 deletions

View File

@ -76,6 +76,7 @@ export class Response {
constructor(responseOptions: ResponseOptions) {
this._body = responseOptions.body;
this.status = responseOptions.status;
this.ok = (this.status >= 200 && this.status <= 299);
this.statusText = responseOptions.statusText;
this.headers = responseOptions.headers;
this.type = responseOptions.type;

View File

@ -0,0 +1,24 @@
import {
describe,
expect,
it,
} from 'angular2/testing_internal';
import {ResponseOptions} from 'angular2/src/http/base_response_options';
import {Response} from 'angular2/src/http/static_response';
export function main() {
describe('Response', () => {
it('should be ok for 200 statuses', () => {
expect(new Response(new ResponseOptions({status: 200})).ok).toEqual(true);
expect(new Response(new ResponseOptions({status: 299})).ok).toEqual(true);
});
it('should not be ok for non 200 statuses', () => {
expect(new Response(new ResponseOptions({status: 199})).ok).toEqual(false);
expect(new Response(new ResponseOptions({status: 300})).ok).toEqual(false);
});
});
}