0
我創建像這樣的自定義http服務post在每個請求中添加標頭。使用自定義http換行從http observable捕獲錯誤
@Injectable()
export class HttpClient {
constructor(public http: Http) {
}
prepareH(hde: Headers){
hde.append("Authorization","Bearer "+XXXXX)
}
get(url) {
let headers = new Headers();
this.prepareH(headers);
return this.http.get(url, {
headers: headers
})
}
}
然後在主網頁,我作出這樣
this.httpclient.get('http://someurl/xxxx').subscribe(
res=>{
console.log(res)
},
err=>{
console.log(err)
}
)
http請求它做工精細我能得到響應在res塊,但HTTP錯誤4XX或500永遠不會犯錯塊。我不知道爲什麼?我怎樣才能解決這個問題?