Pipe not correctly mapping and error handling Angular

4224 views angular

I have a method in a service which returns an Observable. When I subscribe to the observable when I call the method in my component everything works fine and i get my account properly:

    .subscribe(account =>{

However when I tried to implement this using a pipe with a map and catchError it returns nothing.

        map(account => {
        catchError((error: Error) => {
            //Do some error stuff
            return of(null);

The method in the service I call looks like this:

getAccountDetails(u:String): Observable<Object> { }

Obviously I must have some annoying syntax error, but for the love of God I can't find it. Please help!

answered question

You must subscribe(), otherwise the request is never sent, and the pipeline of operations is never executed. map() is supposed to transform an event into something else, not to trigger side-effects.

You're not returning anything from map()

1 Answer


Change it to something like this, as JB Nizet mentioned in the comment, you must subscribe,

.subscribe((username) => this.podcasts.push(username););


   errorHandler(error: Error): Observable<any> {
    console.error('ERROR HANDLER', error);
    return new EmptyObservable();

posted this

Have an answer?


Please login first before posting an answer.