From df4d12cfb8a6463ffc0af3c9201e5791827775be Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 14 Jul 2017 10:04:55 +0200 Subject: [PATCH] Catch errors in account service. --- src/accounts/account.service.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/accounts/account.service.ts b/src/accounts/account.service.ts index 05a3a43..99a17ce 100644 --- a/src/accounts/account.service.ts +++ b/src/accounts/account.service.ts @@ -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 { 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 { 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()); } }