| .. | .. |
|---|
| 1 | +import { LocaleService } from '../common/i18n'; |
|---|
| 2 | +import { BasicService } from '../common/utils'; |
|---|
| 1 | 3 | import { Observable } from 'rxjs/Observable'; |
|---|
| 2 | 4 | import { Http, RequestOptionsArgs, URLSearchParams } from '@angular/http'; |
|---|
| 3 | 5 | |
|---|
| .. | .. |
|---|
| 8 | 10 | } |
|---|
| 9 | 11 | } |
|---|
| 10 | 12 | |
|---|
| 11 | | -export class SeCurisResourceServices { |
|---|
| 12 | | - constructor(protected http: Http, |
|---|
| 13 | +export class SeCurisResourceServices extends BasicService { |
|---|
| 14 | + constructor($L: LocaleService, |
|---|
| 15 | + protected http: Http, |
|---|
| 13 | 16 | protected resource: string) { |
|---|
| 17 | + super($L); |
|---|
| 14 | 18 | } |
|---|
| 15 | 19 | |
|---|
| 16 | 20 | public get(id?: any) : Observable<any> { |
|---|
| 17 | 21 | let url = `${this.resource}/${id || ''}`; |
|---|
| 18 | | - return this.http.get(url).map(response => response.json()); |
|---|
| 22 | + return this.http.get(url).map(response => response.json()).catch(err => super.processErrorResponse(err)); |
|---|
| 19 | 23 | } |
|---|
| 20 | 24 | |
|---|
| 21 | 25 | public create(data: any) : Observable<any> { |
|---|
| 22 | 26 | let url = `${this.resource}`; |
|---|
| 23 | | - return this.http.post(url, JSON.stringify(data)).map(response => response.json()); |
|---|
| 27 | + return this.http.post(url, JSON.stringify(data)).map(response => response.json()).catch(err => super.processErrorResponse(err)); |
|---|
| 24 | 28 | } |
|---|
| 25 | 29 | |
|---|
| 26 | 30 | public modify(id: any, data: any) : Observable<any> { |
|---|
| 27 | 31 | let url = `${this.resource}/${id}`; |
|---|
| 28 | | - return this.http.post(url, JSON.stringify(data)).map(response => response.json()); |
|---|
| 32 | + return this.http.post(url, JSON.stringify(data)).map(response => response.json()).catch(err => super.processErrorResponse(err)); |
|---|
| 29 | 33 | } |
|---|
| 30 | 34 | |
|---|
| 31 | 35 | public remove(id: any) : Observable<any> { |
|---|
| 32 | 36 | let url = `${this.resource}/${id}`; |
|---|
| 33 | | - return this.http.delete(url).map(response => response.json()); |
|---|
| 37 | + return this.http.delete(url).map(response => response.json()).catch(err => super.processErrorResponse(err)); |
|---|
| 34 | 38 | } |
|---|
| 35 | 39 | |
|---|
| 36 | 40 | public action(id: any, action: string, method = 'POST') : Observable<any> { |
|---|
| .. | .. |
|---|
| 44 | 48 | search: (method == 'GET') && new MySearchParams(params) || undefined, |
|---|
| 45 | 49 | body: (method == 'POST') && JSON.stringify(params) || undefined |
|---|
| 46 | 50 | }; |
|---|
| 47 | | - return this.http.request(url, options).map(response => response.json()); |
|---|
| 51 | + return this.http.request(url, options).map(response => response.json()).catch(err => super.processErrorResponse(err)); |
|---|
| 48 | 52 | } |
|---|
| 53 | + |
|---|
| 54 | + |
|---|
| 49 | 55 | } |
|---|