Catch errors in account service.

This commit is contained in:
Alexis Lahouze 2017-07-14 10:04:55 +02:00
parent 1e94109910
commit df4d12cfb8

View File

@ -4,6 +4,7 @@ import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { Logger } from "@nsalaun/ng-logger";
@ -20,11 +21,13 @@ export class AccountService {
query(): Observable<Account[]> {
this.logger.log("Query accounts");
return this.http.get(this.url)
.catch((res: Response) => Observable.throw(res.json()))
.map((res: Response) => res.json());
}
get(id: number): Observable<Account> {
return this.http.get(this.url + '/' + id)
.catch((res: Response) => Observable.throw(res.json()))
.map((res: Response) => res.json());
}
@ -34,6 +37,7 @@ export class AccountService {
let body = JSON.stringify(account);
return this.http.post(this.url, body, options)
.catch((res: Response) => Observable.throw(res.json()))
.map((res: Response) => res.json());
}
@ -43,6 +47,7 @@ export class AccountService {
let body = JSON.stringify(account);
return this.http.post(this.url + '/' + account.id, body, options)
.catch((res: Response) => Observable.throw(res.json()))
.map((res: Response) => res.json());
}
@ -51,6 +56,7 @@ export class AccountService {
let options = new RequestOptions({ headers: headers });
return this.http.delete(this.url + '/' + account.id)
.catch((res: Response) => Observable.throw(res.json()))
.map((res: Response) => res.json());
}
}