Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda