rxjs:EmptyError:顺序没有元素

时间:2018-06-23 16:13:58

标签: angular rxjs angular6

我遇到错误

  

“ EmptyError:我没有顺序的元素”错误   本地主机:8080。

我见过线程https://github.com/yamad/r2d3-decision-tree,但似乎没有答案。

我有"rxjs": "^5.5.6",并且在我的路线中,我尝试添加pathMatch: 'full',,但错误仍然显示。

提取我的app-routing-module.ts

const routes: Routes = [
    {
        pathMatch: 'full', /* added recently for test purposes*/
        path: '',
        component: RootComponent,
        canActivate: [AuthGuard],
        children: [
            {
                pathMatch: 'full', /* added recently for test purposes*/
                path: '',
                component: RootLoggedComponent
            },

这只是在我添加了HTTP拦截器之后才发生的:

export class myInterceptor implements HttpInterceptor {
    constructor(
        private router: Router
    ) {

    }

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

        return next.handle(request)
            .pipe(catchError(err => {
                if (err instanceof HttpErrorResponse) {
                    if (err.status === 401) {
                        this.router.navigate(['/login']);
                    }
                }
                return Observable.empty<HttpEvent<any>>();
            }));
    }
}

编辑:

这是在控制台上打印的完整堆栈跟踪:

ERROR Error: Uncaught (in promise): EmptyError: no elements in sequence
EmptyError: no elements in sequence
    at new EmptyError (EmptyError.js:22)
    at FirstSubscriber.push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._complete (first.js:148)
    at FirstSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at FilterSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at new EmptyError (EmptyError.js:22)
    at FirstSubscriber.push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._complete (first.js:148)
    at FirstSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at MapSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete (Subscriber.js:120)
    at FilterSubscriber.push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._complete (Subscriber.js:138)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4751)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
    at invokeTask (zone.js:1540)
defaultErrorLogger @ core.js:1449
push../node_modules/@angular/core/esm5/core.js.ErrorHandler.handleError @ core.js:1510
next @ core.js:5508
schedulerFn @ core.js:4342
push../node_modules/rxjs/_esm5/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:243
push../node_modules/rxjs/_esm5/Subscriber.js.SafeSubscriber.next @ Subscriber.js:190
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._next @ Subscriber.js:131
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/Subject.js.Subject.next @ Subject.js:56
push../node_modules/@angular/core/esm5/core.js.EventEmitter.emit @ core.js:4322
(anonymous) @ core.js:4782
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138
push../node_modules/@angular/core/esm5/core.js.NgZone.runOutsideAngular @ core.js:4708
onHandleError @ core.js:4782
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:392
push../node_modules/zone.js/dist/zone.js.Zone.runGuarded @ zone.js:154
_loop_1 @ zone.js:677
api.microtaskDrainDone @ zone.js:686
drainMicroTaskQueue @ zone.js:602
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:500
invokeTask @ zone.js:1540
globalZoneAwareCallback @ zone.js:1566
error (async)
customScheduleGlobal @ zone.js:1666
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:407
onScheduleTask @ zone.js:297
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:401
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:232
push../node_modules/zone.js/dist/zone.js.Zone.scheduleEventTask @ zone.js:258
(anonymous) @ zone.js:1831
(anonymous) @ http.js:2353
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/catchError.js.CatchOperator.call @ catchError.js:80
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/observable/ScalarObservable.js.ScalarObservable._subscribe @ ScalarObservable.js:51
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/filter.js.FilterOperator.call @ filter.js:61
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/catchError.js.CatchOperator.call @ catchError.js:80
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/first.js.FirstOperator.call @ first.js:71
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/observable/ArrayObservable.js.ArrayObservable._subscribe @ ArrayObservable.js:116
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/every.js.EveryOperator.call @ every.js:34
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/observable/ArrayObservable.js.ArrayObservable._subscribe @ ArrayObservable.js:116
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/every.js.EveryOperator.call @ every.js:34
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/observable/ArrayObservable.js.ArrayObservable._subscribe @ ArrayObservable.js:116
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/every.js.EveryOperator.call @ every.js:34
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/every.js.EverySubscriber.notifyComplete @ every.js:54
push../node_modules/rxjs/_esm5/operators/every.js.EverySubscriber._complete @ every.js:71
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete @ Subscriber.js:120
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._complete @ mergeMap.js:143
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete @ Subscriber.js:120
push../node_modules/rxjs/_esm5/observable/ArrayObservable.js.ArrayObservable._subscribe @ ArrayObservable.js:118
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/every.js.EveryOperator.call @ every.js:34
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber.notifyNext @ mergeMap.js:151
push../node_modules/rxjs/_esm5/InnerSubscriber.js.InnerSubscriber._next @ InnerSubscriber.js:25
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/observable/ScalarObservable.js.ScalarObservable._subscribe @ ScalarObservable.js:51
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber.notifyNext @ mergeMap.js:151
push../node_modules/rxjs/_esm5/InnerSubscriber.js.InnerSubscriber._next @ InnerSubscriber.js:25
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/observable/ScalarObservable.js.ScalarObservable._subscribe @ ScalarObservable.js:51
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
subscribeToResult @ subscribeToResult.js:23
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:138
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:135
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:118
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber._next @ Subscriber.js:131
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/map.js.MapSubscriber._next @ map.js:85
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:95
push../node_modules/rxjs/_esm5/operators/last.js.LastSubscriber._complete @ last.js:111
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete @ Subscriber.js:120
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._complete @ mergeMap.js:143
push../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.complete @ Subscriber.js:120
push../node_modules/rxjs/_esm5/observable/ScalarObservable.js.ScalarObservable._subscribe @ ScalarObservable.js:53
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe @ Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:160
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/last.js.LastOperator.call @ last.js:40
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/catchError.js.CatchOperator.call @ catchError.js:80
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:92
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
push../node_modules/rxjs/_esm5/operators/map.js.MapOperator.call @ map.js:57
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe @ Observable.js:157
(anonymous) @ Observable.js:204
ZoneAwarePromise @ zone.js:891
push../node_modules/rxjs/_esm5/Observable.js.Observable.forEach @ Observable.js:200
push../node_modules/@angular/router/esm5/router.js.Router.activateRoutes @ router.js:5544
(anonymous) @ router.js:5505
ZoneAwarePromise @ zone.js:891
push../node_modules/@angular/router/esm5/router.js.Router.runNavigate @ router.js:5436
(anonymous) @ router.js:5391
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388
onInvoke @ core.js:4760
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:387
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138
(anonymous) @ zone.js:872
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:421
onInvokeTask @ core.js:4751
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:420
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:188
drainMicroTaskQueue @ zone.js:595
Promise.then (async)
scheduleMicroTask @ zone.js:578
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:410
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:232
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:252
scheduleResolveOrReject @ zone.js:862
ZoneAwarePromise.then @ zone.js:962
push../node_modules/@angular/core/esm5/core.js.PlatformRef.bootstrapModule @ core.js:5579
./src/main.ts @ main.ts:11
__webpack_require__ @ bootstrap:76
0 @ main.ts:12
__webpack_require__ @ bootstrap:76
checkDeferredModules @ bootstrap:43
webpackJsonpCallback @ bootstrap:30
(anonymous) @ main.js:1

这是我的AuthGuard返回的函数:

isAuthenticated(): Observable<boolean> {
        return this.http.post('/isAuth', {}).pipe(
            map(() => {
                console.log('this is not printed in the console');
                return true;
            }),
            catchError((err) => {
                console.log('this either, strangely enough?');
                this.router.navigate(['/login']);
                return Observable.of(false);
            }));

Edit2:

返回(new HttpResponse())会删除堆栈跟踪,但是会在此函数中创建一个错误(即使用户未登录,它也不会出现在catchError中):

isAuthenticated(): Observable<boolean> {
    return this.http.post('/isAuth', {}).pipe(
        map(() => {
            this.loggedIn.next(true);
            return true;
        }),
        catchError((err) => {
            this.loggedIn.next(false);
            this.router.navigate(['/login']);
            return Observable.of(false);
        }));

1 个答案:

答案 0 :(得分:4)

这看起来与Angular中的这个问题非常相似:https://github.com/angular/angular/pull/24621

在没有匹配项并且源Observable完成时,EmptyError来自last()first()(也许还有single())运算符。

因此,我建议检查您正在使用的所有事件句柄,这些返回句柄为Observable。例如,您有canActivate: [AuthGuard],因此请仔细检查以确保AuthGuard返回一个Observable,该Observable发出某种东西而不仅仅是返回例如。 empty()