rxjs: EmptyError: нет элементов в последовательности - PullRequest
0 голосов
/ 23 июня 2018

Я получаю ошибку

Ошибка EmptyError: нет элементов в последовательности локальный: 8080

Я видел поток Angular 5 EmptyError: нет элементов в последовательности при создании дочерних маршрутов , но ни один из ответов, кажется, не применим.

У меня есть "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 голосов
/ 24 июня 2018

Это выглядит очень похоже на эту проблему в Angular: https://github.com/angular/angular/pull/24621

EmptyError происходит от last() или first() (возможно, single() также) операторов, когда нет соответствующего элемента иисходный объект Observable завершен.

Поэтому я бы рекомендовал проверить все дескрипторы событий, которые вы используете, которые возвращают Observables.Например, у вас есть canActivate: [AuthGuard], поэтому дважды проверьте, что AuthGuard возвращает Observable, который испускает что-то и не возвращает просто, например.empty().

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...