diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-23 16:54:21 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-23 16:54:21 +0200 |
commit | de59c48f5f317018e3f746bbe4a7b7efe00109f2 (patch) | |
tree | bc3d007c5aaed8dc72119763f3b1731c5777f218 /client/src/app/admin/friends | |
parent | def16d33d19153c6583fa8a30634760b3d64d34c (diff) | |
download | PeerTube-de59c48f5f317018e3f746bbe4a7b7efe00109f2.tar.gz PeerTube-de59c48f5f317018e3f746bbe4a7b7efe00109f2.tar.zst PeerTube-de59c48f5f317018e3f746bbe4a7b7efe00109f2.zip |
Client: centralize http res extraction in a service
Diffstat (limited to 'client/src/app/admin/friends')
-rw-r--r-- | client/src/app/admin/friends/shared/friend.service.ts | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/client/src/app/admin/friends/shared/friend.service.ts b/client/src/app/admin/friends/shared/friend.service.ts index e4e680c29..75826fc17 100644 --- a/client/src/app/admin/friends/shared/friend.service.ts +++ b/client/src/app/admin/friends/shared/friend.service.ts | |||
@@ -1,9 +1,8 @@ | |||
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { Response } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Observable'; | 2 | import { Observable } from 'rxjs/Observable'; |
4 | 3 | ||
5 | import { Friend } from './friend.model'; | 4 | import { Friend } from './friend.model'; |
6 | import { AuthHttp, AuthService } from '../../../shared'; | 5 | import { AuthHttp, RestExtractor } from '../../../shared'; |
7 | 6 | ||
8 | @Injectable() | 7 | @Injectable() |
9 | export class FriendService { | 8 | export class FriendService { |
@@ -11,13 +10,15 @@ export class FriendService { | |||
11 | 10 | ||
12 | constructor ( | 11 | constructor ( |
13 | private authHttp: AuthHttp, | 12 | private authHttp: AuthHttp, |
14 | private authService: AuthService | 13 | private restExtractor: RestExtractor |
15 | ) {} | 14 | ) {} |
16 | 15 | ||
17 | getFriends(): Observable<Friend[]> { | 16 | getFriends(): Observable<Friend[]> { |
18 | return this.authHttp.get(FriendService.BASE_FRIEND_URL) | 17 | return this.authHttp.get(FriendService.BASE_FRIEND_URL) |
19 | .map(res => <Friend[]>res.json()) | 18 | // Not implemented as a data list by the server yet |
20 | .catch(this.handleError); | 19 | // .map(this.restExtractor.extractDataList) |
20 | .map((res) => res.json()) | ||
21 | .catch((res) => this.restExtractor.handleError(res)); | ||
21 | } | 22 | } |
22 | 23 | ||
23 | makeFriends(notEmptyUrls) { | 24 | makeFriends(notEmptyUrls) { |
@@ -26,18 +27,13 @@ export class FriendService { | |||
26 | }; | 27 | }; |
27 | 28 | ||
28 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) | 29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) |
29 | .map(res => res.status) | 30 | .map(this.restExtractor.extractDataBool) |
30 | .catch(this.handleError); | 31 | .catch((res) => this.restExtractor.handleError(res)); |
31 | } | 32 | } |
32 | 33 | ||
33 | quitFriends() { | 34 | quitFriends() { |
34 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | 35 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') |
35 | .map(res => res.status) | 36 | .map(res => res.status) |
36 | .catch(this.handleError); | 37 | .catch((res) => this.restExtractor.handleError(res)); |
37 | } | ||
38 | |||
39 | private handleError (error: Response) { | ||
40 | console.error(error); | ||
41 | return Observable.throw(error.json().error || 'Server error'); | ||
42 | } | 38 | } |
43 | } | 39 | } |