Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30c4352

Browse files
simon-ramsaynexus-uw
simon-ramsay
authored andcommitted
fix(http) : set response.ok based on given status code
Closes angular#8056
1 parent 45f5df3 commit 30c4352

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

modules/angular2/src/http/static_response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class Response {
7676
constructor(responseOptions: ResponseOptions) {
7777
this._body = responseOptions.body;
7878
this.status = responseOptions.status;
79+
this.ok = (this.status >= 200 && this.status <= 299);
7980
this.statusText = responseOptions.statusText;
8081
this.headers = responseOptions.headers;
8182
this.type = responseOptions.type;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
describe,
3+
expect,
4+
it,
5+
} from 'angular2/testing_internal';
6+
7+
import {ResponseOptions} from 'angular2/src/http/base_response_options';
8+
import {Response} from 'angular2/src/http/static_response';
9+
10+
11+
12+
export function main() {
13+
describe('Response', () => {
14+
it('should be ok for 200 statuses', () => {
15+
expect(new Response(new ResponseOptions({status: 200})).ok).toEqual(true);
16+
expect(new Response(new ResponseOptions({status: 299})).ok).toEqual(true);
17+
});
18+
19+
it('should not be ok for non 200 statuses', () => {
20+
expect(new Response(new ResponseOptions({status: 199})).ok).toEqual(false);
21+
expect(new Response(new ResponseOptions({status: 300})).ok).toEqual(false);
22+
});
23+
});
24+
}

0 commit comments

Comments
 (0)