Answer the question
In order to leave comments, you need to log in
Why doesn't error handling work correctly?
I have this method
editStatusUser(id : number, status : string) :Observable<boolean> {
return this.http.get('assets/fake/fake-userss.json')
.map((response: Response) => {
// Todo: Delete on real data
return Math.round(Math.random());
})
.delay(2000)
.catch((error: Response) => this.handleError(error));
}
private handleError (error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
console.log(error.json());
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question