10

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);
        }));
sarahwc5
  • 391
  • 3
  • 4
  • 10
  • 2
    Can someone please explain why I'm receiving down votes for this question ? If it is unclear or lacks info, feel free to ask for me to add it and I'll edit it. – sarahwc5 Jun 23 '18 at 16:24
  • 1
    did you get the solution. Please share. – Mahi Oct 08 '18 at 14:11

1 Answers1

13

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

The EmptyError comes from last(), first() and firstValueFrom() (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().

L8Cod3r
  • 60
  • 6
martin
  • 93,354
  • 25
  • 191
  • 226
  • I'm new to angular so I'm unsure I've fully grasped the meaning of your answer, so I've added some more info by editing my original question with some info that seems related to your answer, in hopes you can help me figure out what I did wrong, if anything. – sarahwc5 Jun 24 '18 at 18:21
  • Yeah, that's what I was thinking. You can see in your stacktrace that the error comes from the `first()` operator and it's most likely because you're returning `Observable.empty()` in `myInterceptor`. – martin Jun 24 '18 at 20:36
  • I somehow figured that's what you were talking about, which is why I added this info, but I still don't understand the root cause: am I doing something wrong, should I do something differently, or is it a bug? In other words, how to remove this error log from the client? – sarahwc5 Jun 24 '18 at 20:51
  • Don't return an empty Observable with `Observable.empty()`. Return some value eg. `Observable.of(whatever)` or rethrow the error `Observable.throw(err)`. – martin Jun 24 '18 at 21:10
  • I tried changing it to return Observable.of(false); (and changing the signature to Observable), but I still get the same error – sarahwc5 Jun 24 '18 at 21:32
  • @sarahwc5 It was tricky but you need to return a type compatible with `HttpEvent`. That's for example en instance of `HttpResponse` https://stackblitz.com/edit/angular-6jtgbb?file=src/app/interceptor.ts – martin Jun 25 '18 at 09:56
  • Thanks. It does indeed remove the stacktrace, however it creates another bug in my app :(... And just reverting to Observable.of(false) removes the bug, so it's related to the return value. I don't know if I'll be able to reproduce it on stackblitz without copying my whole app there (and the server...) but I tried to edit the question to reflect my new problem – sarahwc5 Jun 25 '18 at 17:50
  • any idea what could cause this? – sarahwc5 Jun 27 '18 at 09:14
  • I still can't solve this issue, if you could please have a look at my edit – sarahwc5 Jul 03 '18 at 19:17
  • I still can't solve this issue, if you could please have a look at my edit @martin – sarahwc5 Jul 03 '18 at 19:18
  • Can you please help @martin ? – sarahwc5 Jul 11 '18 at 17:10