Encountering an error specifically when attempting to return a value from the catch
block. Wondering if there is a mistake in the approach. Why is it not possible to return an observable
from catch
?
.ts
getMyTopic() {
return this.topicSer.getMyTopics().map((res: any) => res.json()).map((res: any) => res = res.categories)
.catch((err: any) => {
console.log('err', err);
return []
})
}
provider.ts
getMyTopics(): Observable<any> {
if (typeof this.userService.userDetails != 'undefined') {
this.localCacheService.getItem(this.localCacheService.discoverTopicsKey).then((val) => {
if (val != null && val.length == 0) return this.apiService.get(config.discover_topic_WITHAUTH);
}).catch(() => {
return this.apiService.get(config.discover_topic_WITHOUTAUTH);//here is the issue
});
}
Error
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined
TypeError: Cannot read property 'map' of undefined
at Discover.webpackJsonp.402.Discover.getMyTopic (discover.ts:123)
at Discover.webpackJsonp.402.Discover.getData (discover.ts:69)
at discover.ts:51
...
...
...
/* Several lines of error messages */