Currently, I have a function called getElementList() which returns Observable<Element[]>. The goal is to handle different scenarios based on the user's current page - two cases for two specific pages and one error case. However, I am struggling to implement an error return for an Observable<Element[]>.
getElementList(): Observable<Element[]> {
const isOnClubsPage: boolean = this.router.url.endsWith('/Clubs');
const isOnPartenairePage: boolean = this.router.url.endsWith('/Partenaires');
if (isOnClubsPage) {
return this.http.get<Element[]>('api/Clubs').pipe(
tap((clubList) => this.log(clubList)),
catchError((error) => this.handleError(error, []))
);
}
else if(isOnPartenairePage){
return this.http.get<Element[]>('api/Partenaires').pipe(
tap((clubList) => this.log(clabList)),
catchError((error) => this.handleError(error, []))
);
}else{
// Here is where I struggle with returning an error
return error??
}
}
I'm looking for a way to effectively throw an error in the final 'else' statement but haven't found a solution yet.