我正在创建一个服务“错误拦截器”,但当我尝试实例化一个HttpRequest时,它不允许。
我是Angular和Web App的新手。
这是我的尝试
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpEvent, HttpErrorResponse } from '@angular/common/http';
import { HttpRequest } from 'selenium-webdriver/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(catchError(error => {
if (error instanceof HttpErrorResponse) {
const applicationerror = error.headers.get('Application-Error');
if (applicationerror) {
console.log(applicationerror);
return throwError(applicationerror);
}
}
})
);
}
}
发布于 2019-07-24 19:12:35
这是因为您要从selenium-webdriver/http
而不是从@angular/common/http
导入HttpRequest
删除此命令:
import { HttpRequest } from 'selenium-webdriver/http';
然后像这样添加HttpRequest
:
import { HttpInterceptor, HttpHandler, HttpEvent, HttpErrorResponse, HttpRequest } from '@angular/common/http';
https://stackoverflow.com/questions/57189684
复制相似问题