我創造了這個HTTPInterceptor才能夠更好地處理HTTP錯誤,這是工作之前我也做了一個混帳拉就跑NPM安裝。角4的Http攔截:next.handle(...)做的是不是一個函數
這是我的代碼:
import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse} from '@angular/common/http';
import {Observable} from "rxjs";
import {ToasterService} from "angular2-toaster";
@Injectable()
export class GobaeInterceptor implements HttpInterceptor {
constructor(private toasterService: ToasterService){
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req)
.do(event => {
if (event instanceof HttpResponse) {
let response = event.body;
if(response.Error){
this.toasterService.pop('error', 'Error '+response.Code, response.Message);
}
}
});
}
}
,這是錯誤我得到:
TypeError: next.handle(...).do is not a function at GobaeInterceptor.webpackJsonp.../../../../../src/app/services/gobae.interceptor.ts.GobaeInterceptor.intercept (gobae.interceptor.ts:12) at HttpInterceptorHandler.webpackJsonp.../../../common/@angular/common/http.es5.js.HttpInterceptorHandler.handle (
做了一些會影響我的代碼最近改變了嗎?現在我能做些什麼來「捕捉」攔截器上的http響應?因爲你缺少do
運營商拋出
如果攔截器的提供者仍然存在,那麼最好只是比較拉或拉之後的代碼,或者拉之後更改哪些文件。因爲我猜模塊供應商缺失。甚至httpclientmodule –