Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rxjs: EmptyError: no elements in sequence

I am getting an error

'EmptyError: no elements in sequence' error when I go to localhost:8080.

I have seen the thread Angular 5 EmptyError: no elements in sequence while making child routes but none of the answers seem to apply.

I have "rxjs": "^5.5.6" and in my routes, I tried adding pathMatch: 'full', but the error is still displayed.

Extract of my 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
            },

This only happened recently, after I added a http Interceptor:

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>>();
            }));
    }
}

Edit:

This is the full stacktrace that is printed on the console:

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

And this is the function returned by my 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:

returning of(new HttpResponse()) removes the stacktrace, but creates a bug in this function (it doesn't go in the catchError even though the user is not logged in):

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);
        }));
like image 364
sarahwc5 Avatar asked Jun 23 '18 16:06

sarahwc5


1 Answers

This looks very similar to this issue in Angular: https://github.com/angular/angular/pull/24621

The EmptyError comes from last() or first() (maybe single() as well) operators when there's no matching item and the source Observable completes.

So I'd recommend checking all event handles you're using that return Observables. For example you have canActivate: [AuthGuard] so double check that AuthGuard returns an Observable that emits something and doesn't return just eg. empty().

like image 182
martin Avatar answered Oct 24 '22 15:10

martin