小编rsi*_*dia的帖子

如何观察某些组件中的角度5拦截器错误

嗨,我是angular 5的新手,并跟着一些博客写了HTTP拦截器.

export class AngularInterceptor implements HttpInterceptor {
public http404 = false;
constructor() { }

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    console.log("intercepted request ... ");

    // Clone the request to add the new header.
    const httpReq = req.clone(
        {
            headers: req.headers.set("headerName", "headerValue")
        }
    );

    console.log("Sending request with new header now ...");

    //send the newly created request
    return next.handle(httpReq)
        .catch((error, caught) => {
            //intercept the respons error and displace it to the console 
            console.log("Error Occurred");
            if(error.status === 404)
this.http404 = true; …
Run Code Online (Sandbox Code Playgroud)

rxjs angular-http-interceptors angular5

2
推荐指数
1
解决办法
2880
查看次数

标签 统计

angular-http-interceptors ×1

angular5 ×1

rxjs ×1