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

155
Visualizações
I want to initialize my observable when I get 404 response from the API

I want to initialize my observable when I get 404 response from the API I tried this code but it doesn't work

const urlParams = { email: this.email };
this.voicesProfileObservable$ = this.service.request<any>(
  AVAILABLE_SERVICES.GET_USER_PROFILE_VOICES.ID,
  {},
  { urlParams }
).pipe(
  catchError((error) => {
    this.voicesProfileObservable$ = Observable.of({
      aboutSectionType: '',
      aboutCustomizedDescription: '',
      showSpacesFollowed: true,
      showBadgesEarned: true,
      showMobileNumber: true,
      showOfficeNumber: false,
      showEmail: true,
      showSlackHandle: false,
      video: {},
      socialLinks: [],
      personalLinks: [],
    });
    return throwError(error);
}))
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Because you set this.voicesProfileObservable$ more times. Once when you define and declare it as an observable, and second time you do it in catchError().

You should catch the error, and return with of(...data) without throwing the error.

          catchError(_ => of({
            aboutSectionType: '',
            aboutCustomizedDescription: '',
            showSpacesFollowed: true,
            showBadgesEarned: true,
            showMobileNumber: true,
            showOfficeNumber: false,
            showEmail: true,
            showSlackHandle: false,
            video: {},
            socialLinks: [],
            personalLinks: [],
          })

     
about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe try it like this:

this.voicesProfileObservable$ = this.service.request<any>(
  AVAILABLE_SERVICES.GET_USER_PROFILE_VOICES.ID,
  {},
  { urlParams }
).pipe(
  catchError((error) => {
    return of({
      aboutSectionType: '',
      aboutCustomizedDescription: '',
      showSpacesFollowed: true,
      showBadgesEarned: true,
      showMobileNumber: true,
      showOfficeNumber: false,
      showEmail: true,
      showSlackHandle: false,
      video: {},
      socialLinks: [],
      personalLinks: [],
    });
  })
)

You should return the default response directly inside the catchError callback to pass it down the subscribers.

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