I have a function in which I need to return an empty string twice (see return ''. When I use catch error, it is functioning properly. However, I am struggling to modify the function so that the catch error is no longer needed. This is my current function:
agencies$: Observable<Agency[]> = this.afs.collection<Agency[]>('agencies')
.valueChanges()
.pipe(tap(console.log),
mergeMap((agencies: Agency[]) => from(agencies)),
mergeMap((agency: Agency) => {
return forkJoin([
this.afStorage.storage
.refFromURL('gs://agency-logos-paid-keeper')
.child(`/thumbnails/${agency.agencyId}_700x100.png`)
.getDownloadURL().then(url => url).catch(error => {
return '';
}),
this.afStorage.storage
.refFromURL('gs://benefit-cards-paid-keeper').child(`/${agency.agencyId}_200x200.png`)
.getDownloadURL().then(url => url).catch(error => {
return '';
})])
.pipe(
tap(([logoUrl, benefitCardPhotoUrl]) => console.log('a', logoUrl, benefitCardPhotoUrl)),
map(([logoUrl, benefitCardPhotoUrl]) => ({
...agency, logoUrl, benefitCardPhotoUrl
})
), catchError((error) => {
return of({...agency});
}));
}),
map((agency: Agency) => [agency]),
scan((agencies: Agency[], agency: Agency[]) => {
const agencyExists = agencies.find(a => a.agencyId === agency[0].agencyId);
if (!agencyExists) {
return [...agencies, ...agency];
}
return agencies;
}));
I am looking to eliminate the .catch(error) after then (both occurrences), but every attempt results in an error. How can I remove the catch error while still ensuring there is a return statement? It might seem like a basic question, but I'm stuck and unable to solve it.