Catch errors in account service.
This commit is contained in:
parent
1e94109910
commit
df4d12cfb8
@ -4,6 +4,7 @@ import { Http, Headers, RequestOptions, Response } from '@angular/http';
|
|||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
|
import 'rxjs/add/operator/catch';
|
||||||
|
|
||||||
import { Logger } from "@nsalaun/ng-logger";
|
import { Logger } from "@nsalaun/ng-logger";
|
||||||
|
|
||||||
@ -20,11 +21,13 @@ export class AccountService {
|
|||||||
query(): Observable<Account[]> {
|
query(): Observable<Account[]> {
|
||||||
this.logger.log("Query accounts");
|
this.logger.log("Query accounts");
|
||||||
return this.http.get(this.url)
|
return this.http.get(this.url)
|
||||||
|
.catch((res: Response) => Observable.throw(res.json()))
|
||||||
.map((res: Response) => res.json());
|
.map((res: Response) => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
get(id: number): Observable<Account> {
|
get(id: number): Observable<Account> {
|
||||||
return this.http.get(this.url + '/' + id)
|
return this.http.get(this.url + '/' + id)
|
||||||
|
.catch((res: Response) => Observable.throw(res.json()))
|
||||||
.map((res: Response) => res.json());
|
.map((res: Response) => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +37,7 @@ export class AccountService {
|
|||||||
let body = JSON.stringify(account);
|
let body = JSON.stringify(account);
|
||||||
|
|
||||||
return this.http.post(this.url, body, options)
|
return this.http.post(this.url, body, options)
|
||||||
|
.catch((res: Response) => Observable.throw(res.json()))
|
||||||
.map((res: Response) => res.json());
|
.map((res: Response) => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +47,7 @@ export class AccountService {
|
|||||||
let body = JSON.stringify(account);
|
let body = JSON.stringify(account);
|
||||||
|
|
||||||
return this.http.post(this.url + '/' + account.id, body, options)
|
return this.http.post(this.url + '/' + account.id, body, options)
|
||||||
|
.catch((res: Response) => Observable.throw(res.json()))
|
||||||
.map((res: Response) => res.json());
|
.map((res: Response) => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +56,7 @@ export class AccountService {
|
|||||||
let options = new RequestOptions({ headers: headers });
|
let options = new RequestOptions({ headers: headers });
|
||||||
|
|
||||||
return this.http.delete(this.url + '/' + account.id)
|
return this.http.delete(this.url + '/' + account.id)
|
||||||
|
.catch((res: Response) => Observable.throw(res.json()))
|
||||||
.map((res: Response) => res.json());
|
.map((res: Response) => res.json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user