Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
How do I handle catching errors in multiple places in Angular stream?

right now I am trying to make sure I am handling errors correctly in a stream that first gets the id of a group, and then uses that group id to get profile information.

I need it so it's obvious which step is causing the error -- either the get groupId or the get profile info.

Right now I have something like this, but I am unsure if this is correct.

this.groupRepository
    .getUserGroup()
    .pipe(mergeMap(group) => {
        return this.profileRepository.getAllProfiles(group.id)
    })
    .subscribe(
        (res) => {
            // doing things in here to set the groups and profiles
        },
        (error) => {
            this.error = error;
        }
    );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are doing it correctly.

Errors from both methods would end up in (error) => {...} method.

Small tests to play with:

of('A', 'B', 'C').pipe(mergeMap(letter => {
  return of('E', 'F', 'G');
})).subscribe(
    (res) => {
      console.log(res);
    },
    (error) => {
      console.log(error);
    }
  );

Returns: 'E', 'F', 'G', 'E', 'F', 'G'

With second method throws:

of('A', 'B', 'C').pipe(mergeMap(letter => {
  return throwError('bad');
})).subscribe(
    (res) => {
      console.log(res);
    },
    (error) => {
      console.log(error);
    }
  );

Returns: "bad"

With first method throws:

throwError('bad').pipe(mergeMap(letter => {
  return of('E', 'F', 'G');
})).subscribe(
    (res) => {
      console.log(res);
    },
    (error) => {
      console.log(error);
    }
  );

Returns: "bad"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!