rxjs中的长堆栈跟踪

时间:2018-01-29 15:41:57

标签: javascript rxjs rxjs5

RxJS 5中长堆栈跟踪的解决方案是什么?即包含异步调用的堆栈跟踪,导致抛出错误。

我已经看过旧版本的各种黑客攻击,但除​​了开发人员正在开发的承诺之外,这个版本没有任何内容。

例如,我遇到了以下堆栈跟踪:

TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at Object.subscribeToResult (MyProject\node_modules\src\util\subscribeToResult.ts:82:23)
    at MergeMapSubscriber._innerSub (MyProject\node_modules\src\operators\mergeMap.ts:138:14)
    at MergeMapSubscriber._tryNext (MyProject\node_modules\src\operators\mergeMap.ts:134:10)
    at MergeMapSubscriber._next (MyProject\node_modules\src\operators\mergeMap.ts:118:12)
    at MergeMapSubscriber.Subscriber.next (MyProject\node_modules\src\Subscriber.ts:96:12)
    at ArrayObservable._subscribe (MyProject\node_modules\src\observable\ArrayObservable.ts:124:20)
    at ArrayObservable.Observable._trySubscribe (MyProject\node_modules\src\Observable.ts:217:19)
    at ArrayObservable.Observable.subscribe (MyProject\node_modules\src\Observable.ts:202:87)
    at MergeMapOperator.call (MyProject\node_modules\src\operators\mergeMap.ts:92:19)
    at Observable.subscribe (MyProject\node_modules\src\Observable.ts:200:16)
    at Object.subscribeToResult (MyProject\node_modules\src\util\subscribeToResult.ts:34:21)
    at MergeMapSubscriber._innerSub (MyProject\node_modules\src\operators\mergeMap.ts:138:14)
    at MergeMapSubscriber._tryNext (MyProject\node_modules\src\operators\mergeMap.ts:134:10)
    at MergeMapSubscriber._next (MyProject\node_modules\src\operators\mergeMap.ts:118:12)
    at MergeMapSubscriber.Subscriber.next (MyProject\node_modules\src\Subscriber.ts:96:12)
    at ArrayObservable._subscribe (MyProject\node_modules\src\observable\ArrayObservable.ts:124:20)
    at ArrayObservable.Observable._trySubscribe (MyProject\node_modules\src\Observable.ts:217:19)
    at ArrayObservable.Observable.subscribe (MyProject\node_modules\src\Observable.ts:202:87)
    at MergeMapOperator.call (MyProject\node_modules\src\operators\mergeMap.ts:92:19)
    at Observable.subscribe (MyProject\node_modules\src\Observable.ts:200:16)
    at Observable._subscribe (MyProject\node_modules\src\Observable.ts:275:24)
    at Observable.subscribe (MyProject\node_modules\src\Observable.ts:202:63)

现在,这绝对是一个100%的用户错误,可以链接到我自己的代码的某些部分,但它无法确定它来自何处。

1 个答案:

答案 0 :(得分:0)

当您使用.catch块并且请求与 mergeMap 异步时,最有可能出现此类错误。

你应该从catch块中返回observable。

 .catch((response) => {
        // Do your things here
        return Rx.Observable.empty();
    });

是的,这不是一个理想的答案:(

祝你好好调试!