Tin*_*ter 5 http try-catch typescript angular
我想捕获所有http错误,以通知用户发生的问题.
所以,我创建了一个使用catch执行http get的方法.
get(path: string): Promise<any> {
let headers = new Headers();
return this.http.get(path, { headers: headers })
.toPromise()
.then(response => { ... })
.catch((response: Response) => { this.errorHandler(response); });
}
Run Code Online (Sandbox Code Playgroud)
当path参数为'/ fault-url'时,catch按预期处理.
但是当路径为' http:// localhost:5000/fault-url '时,catch方法不会捕获错误.我已经将日志记录添加到所有不同的地方,但它接收get方法只是中止.控制台日志显示以下错误
选项http:// localhost:5000/fault-url net :: ERR_CONNECTION_REFUSED
EXCEPTION:响应状态:URL为0:null
未捕获的响应{_body:ProgressEvent,status:0,ok:false,statusText:"",headers:Headers ...}
http真的中止还是我做错了什么?
| 归档时间: |
|
| 查看次数: |
2314 次 |
| 最近记录: |