catchError函数中Angular 10中的HttpInterceptor管道错误

问题描述

类型'(error:any)=> void'的参数不能分配给类型'(err:any,catch:Observable )=> ObservableInput'的参数。 不能将类型“ void”分配给类型“ ObservableInput”。

enter image description here

代码

import { HttpErrorResponse,HttpEvent,HttpHandler,HttpInterceptor,HttpRequest,HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable,throwError } from 'rxjs';
import { catchError,map,skip,retry,tap } from 'rxjs/operators';


@Injectable()
export class AuthenticationInterceptor implements HttpInterceptor {

    API_SERVER_BASE_URL = "http://localhost:5000/api/v1";
    urlsToNotUse: Array<string>;

    constructor() {
        this.urlsToNotUse = [
            '/user/login',.....
        ];
    }


    intercept(req: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
        const ACCESS_TOKEN = localStorage.getItem("accessToken");
        // if accesstoken is not null
        if (ACCESS_TOKEN && this.isValidRequestForInterceptor(req.url)) {
         .........
         .........
        } else {
            const reqWithoutAuth = req.clone({
                url: this.API_SERVER_BASE_URL + req.url,});
            return next.handle(reqWithoutAuth)
                .pipe(
                    tap(evt => { }),catchError(error => {
                        console.log(error);
                     })
                );
        }
    }


    private isValidRequestForInterceptor(requestUrl: string): boolean {
        return !this.urlsToNotUse.includes(requestUrl);
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)