Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda