Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度2:未捕获504错误(网关超时)_Javascript_Php_Angular_Typescript_Angular2 Http - Fatal编程技术网

Javascript 角度2:未捕获504错误(网关超时)

Javascript 角度2:未捕获504错误(网关超时),javascript,php,angular,typescript,angular2-http,Javascript,Php,Angular,Typescript,Angular2 Http,我的Angular 2应用程序中的错误处理有问题。 当后端服务器脱机时,我在控制台中收到以下未捕获的错误: 得到 504(网关超时) 服务中的我的http.get如下所示: getData(): Observable<any> { let apiUrl = `${API_URL}data`; this.http.get(apiUrl) .map((res => res.json() || [])) .subscribe(response => { let

我的Angular 2应用程序中的错误处理有问题。 当后端服务器脱机时,我在控制台中收到以下未捕获的错误:

得到 504(网关超时)

服务中的我的http.get如下所示:

getData(): Observable<any> {

let apiUrl = `${API_URL}data`;
this.http.get(apiUrl)
  .map((res => res.json() || []))
  .subscribe(response => {
    let data = [];
    let index = 0;
    if (typeof(response.data) !== 'undefined' && response.success !== false) {
      // add index to each entry
      response.data.forEach(entry => {
        data.push({
          id: index++,
          title: entry.title,
          others: entry.others
        });
      });
      this.dataCollection = data;
      this.subject.next(data);
    }
  }, error => {
    this.subject.error("The Server could not be reached. Please wait until a connection can be established, or reload the page.");
  });

    return this.subject.asObservable();
} 
getData():可观察{
设apiUrl=`${API_URL}数据`;
this.http.get(apirl)
.map((res=>res.json()| |[]))
.订阅(响应=>{
让数据=[];
设指数=0;
if(typeof(response.data)!='undefined'&&response.success!==false){
//为每个条目添加索引
response.data.forEach(条目=>{
数据推送({
id:index++,
标题:entry.title,
其他:其他
});
});
this.dataCollection=数据;
本.subject.next(数据);
}
},错误=>{
this.subject.error(“无法访问服务器。请等待建立连接,或重新加载页面。”);
});
返回此.subject.asObservable();
} 

如何防止Angular 2将此错误发送到控制台?

如果不知道您对HTTP请求使用的依赖关系,几乎不可能确定您的问题

我最近在TypeScript中回答了另一个关于HTTP(s)请求的问题:


希望这有帮助:)

我认为你做不到;即使应用程序处理它时没有错误,浏览器也“知道”请求已失败。