Angular 处理http.get()中的错误
我正在尝试使用以下代码访问端点URLAngular 处理http.get()中的错误,angular,http,ionic-framework,error-handling,Angular,Http,Ionic Framework,Error Handling,我正在尝试使用以下代码访问端点URL this.http.get<IApiResponse>(this.endpointURL, {headers: headers, params: params}).subscribe( (response:IApiResponse) => { // handle response }, error => {
this.http.get<IApiResponse>(this.endpointURL, {headers: headers, params: params}).subscribe(
(response:IApiResponse) => {
// handle response
},
error => {
// handle error
console.log(error);
}
);
及
第二个输出似乎来自console.log(错误)代码>,但这一条没有给我任何有用的信息(“未知错误”
)。我不知道第一条错误消息是从哪里来的(控制台中的背景是红色的),但这条消息包含了实际有用的信息,我无法访问它
我怎样才能确定问题出在哪里
error => {
}
范围?您可以这样做:
import { Response } from '@angular/http';
(error: Response) => {
const text = error.text();
console.log(text);
});
但我猜这仍然会抛出“未知错误”
在我看来,这是一条信息
GET https://endpoint/file.php?someParams net::ERR_INTERNET_DISCONNECTED
派生自浏览器本身,Angular无法访问。是的,您可以假设服务器没有出现状态为0的错误,因此可能是连接错误。
import { Response } from '@angular/http';
(error: Response) => {
const text = error.text();
console.log(text);
});
GET https://endpoint/file.php?someParams net::ERR_INTERNET_DISCONNECTED