相关疑难解决方法(0)

HTTP拦截器使用Angular 2,4,6,7,8,9 TypeScript在失败的请求上获得状态0

我有以下 HTTP 拦截器的实现Angular ^4.3.6

import {Injectable} from "@angular/core";
import {
  HttpInterceptor,
  HttpHandler,
  HttpRequest,
  HttpEvent,
  HttpResponse,
  HttpErrorResponse
} from "@angular/common/http";
import {Observable} from "rxjs/Observable";
import "rxjs/add/operator/do";

@Injectable()
export class InterceptorService implements HttpInterceptor {

  intercept(
    req: HttpRequest<any>,
    next: HttpHandler
): Observable<HttpEvent<any>> {
    return next.handle(req).do(evt => {
      console.log(evt);//this logs the success message properly
      if (evt instanceof HttpResponse) {
        //Keep going
      }
    },err => {
    console.log(err);
    //this logs the error but don't have useful info in it.
    });

}
}
Run Code Online (Sandbox Code Playgroud)

在成功的 http …

http web-deployment typescript angular-http-interceptors angular

4
推荐指数
1
解决办法
9115
查看次数