角度httpClient中的捕获错误仍然记录401

时间:2018-06-11 01:24:23

标签: angular rxjs angular6

我在浏览器控制台日志中收到以下错误堆栈跟踪。

GET http://localhost/login/authAjax 401 ()
scheduleTask    @   zone.js:2969
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.scheduleMacroTask @   zone.js:255
scheduleMacroTaskWithCurrentZone    @   zone.js:1114
(anonymous) @   zone.js:3001
proto.(anonymous function)  @   zone.js:1394
(anonymous) @   http.js:2364
push../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe   @   Observable.js:172
push../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe   @   Observable.js:160
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/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/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/first.js.FirstSubscriber._emitFinal    @   first.js:136
push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._emit @   first.js:119
push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._tryPredicate @   first.js:111
push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._next @   first.js:95
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/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/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/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/first.js.FirstSubscriber._emitFinal    @   first.js:136
push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._emit @   first.js:119
push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._tryPredicate @   first.js:111
push../node_modules/rxjs/_esm5/operators/first.js.FirstSubscriber._next @   first.js:95
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/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/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
subscribeToResult   @   subscribeToResult.js:17
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/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/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/first.js.FirstOperator.call    @   first.js:71
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
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

当我运行以下代码时会发生这种情况:

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

在服务器端,/ isAuthenticated重定向到/ login / authAjax,返回401.我想捕获此错误并导航到/ login。

但是我不明白如何防止写入日志,因为它似乎是在我自己编写的'In catchError'之前编写的。

如果我忘记添加相关信息,请向我提出进一步的详细信息。

0 个答案:

没有答案