简体   繁体   English

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ map”

[英]ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined

The below error happens only when it tries to return value from the catch . 仅当它尝试从catch返回值时,才会发生以下错误。 Hope I'm doing a fundamentally wrong thing here.Please give me a clue.Why can't I return an observable from catch ? 希望我在这里做的是根本错误的事情。请给我一个提示。为什么我不能从catch返回observable到的东西?

.ts .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 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
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (core.js:4626)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.js:4617)
    at Discover.webpackJsonp.402.Discover.getMyTopic (discover.ts:123)
    at Discover.webpackJsonp.402.Discover.getData (discover.ts:69)
    at discover.ts:51
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (core.js:4626)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.js:4617)
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.js:4617)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)
    at e.invokeTask [as invoke] (polyfills.js:3)
    at p (polyfills.js:2)
    at IDBRequest.v (polyfills.js:2)
defaultErrorLogger @ core.js:1350
ErrorHandler.handleError @ core.js:1411
IonicErrorHandler.handleError @ ionic-error-handler.js:61
next @ core.js:5373
schedulerFn @ core.js:4220
SafeSubscriber.__tryOrUnsub @ Subscriber.js:238
SafeSubscriber.next @ Subscriber.js:185
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ core.js:4200
(anonymous) @ core.js:4648
t.invoke @ polyfills.js:3
r.run @ polyfills.js:3
NgZone.runOutsideAngular @ core.js:4574
onHandleError @ core.js:4648
t.handleError @ polyfills.js:3
r.runGuarded @ polyfills.js:3
(anonymous) @ polyfills.js:3
n.microtaskDrainDone @ polyfills.js:3
o @ polyfills.js:3
e.invokeTask @ polyfills.js:3
p @ polyfills.js:2
v @ polyfills.js:2
IndexedDB (async)
(anonymous) @ localforage.js:826
t.invoke @ polyfills.js:3
onInvoke @ core.js:4626
t.invoke @ polyfills.js:3
r.run @ polyfills.js:3
(anonymous) @ polyfills.js:3
t.invokeTask @ polyfills.js:3
onInvokeTask @ core.js:4617
t.invokeTask @ polyfills.js:3
r.runTask @ polyfills.js:3
o @ polyfills.js:3
e.invokeTask @ polyfills.js:3
p @ polyfills.js:2
v @ polyfills.js:2

The getMyTopics method doesn't return anything. getMyTopics方法不返回任何内容。 Also the catch operator is returning an empty array when it should return an Observable. catch操作符应返回Observable时,它还将返回一个空数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“id” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'id' of undefined 错误错误:未捕获(承诺):类型错误:无法读取未定义的属性“key” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'key' of undefined 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ nativeElement” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'nativeElement' of undefined 角度7-错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ map” - Angular 7- ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined 错误:未捕获(承诺):TypeError:无法读取未定义的属性“ customerName” - Error: Uncaught (in promise): TypeError: Cannot read property 'customerName' of undefined “错误:未捕获(在承诺中):TypeError:无法读取未定义的属性”长度“ - “Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined” 错误:未捕获(承诺):TypeError:无法读取未定义的属性“ title” - Error: Uncaught (in promise): TypeError: Cannot read property 'title' of undefined 错误:未捕获(承诺中):TypeError:无法读取未定义的属性“pushTag” - Error: Uncaught (in promise): TypeError: Cannot read property 'pushTag' of undefined 错误:未捕获(承诺中):TypeError:无法读取属性 - Error: Uncaught (in promise): TypeError: Cannot read property 业力 | 离子 | 未捕获的错误:未捕获的错误:未捕获(承诺中):TypeError:无法读取未定义的属性“getToken” - Karma | Ionic | Uncaught Error: Uncaught Error: Uncaught (in promise): TypeError: Cannot read property 'getToken' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM