From 30c43521d316426caad01ce19c7e4fd655493c5e Mon Sep 17 00:00:00 2001 From: simon-ramsay Date: Wed, 13 Apr 2016 19:07:20 -0400 Subject: [PATCH] fix(http) : set response.ok based on given status code Closes #8056 --- modules/angular2/src/http/static_response.ts | 1 + .../test/http/static_response_spec.ts | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 modules/angular2/test/http/static_response_spec.ts diff --git a/modules/angular2/src/http/static_response.ts b/modules/angular2/src/http/static_response.ts index c4e986f774..edd80ee851 100644 --- a/modules/angular2/src/http/static_response.ts +++ b/modules/angular2/src/http/static_response.ts @@ -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; diff --git a/modules/angular2/test/http/static_response_spec.ts b/modules/angular2/test/http/static_response_spec.ts new file mode 100644 index 0000000000..844ff96c54 --- /dev/null +++ b/modules/angular2/test/http/static_response_spec.ts @@ -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); + }); + }); +}