Quiero inicializar mi observable cuando recibo una respuesta 404 de la API Probé este código pero no funciona
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); }))Porque configuraste this.voicesProfileObservable$ más veces. Una vez que lo defina y lo declare como observable, y la segunda vez que lo haga en catchError().
Debería detectar el error y regresar con of(...data) sin arrojar el error.
catchError(_ => of({ aboutSectionType: '', aboutCustomizedDescription: '', showSpacesFollowed: true, showBadgesEarned: true, showMobileNumber: true, showOfficeNumber: false, showEmail: true, showSlackHandle: false, video: {}, socialLinks: [], personalLinks: [], })Tal vez intente así:
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: [], }); }) ) Debe devolver la respuesta predeterminada directamente dentro de la devolución de llamada catchError para transmitirla a los suscriptores.