Http 如果API在Angular2中关闭(错误连接被拒绝),如何处理错误?
如果服务器关闭,我的catch error方法不会捕获错误Http 如果API在Angular2中关闭(错误连接被拒绝),如何处理错误?,http,angular,ionic2,observable,Http,Angular,Ionic2,Observable,如果服务器关闭,我的catch error方法不会捕获错误 let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); return this.http.post(this.PATH + '/signup', details, options) .map(res => res.json())
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.PATH + '/signup', details, options)
.map(res => res.json())
.catch(res => Observable.throw(res['_body']));
您可以处理subscribe方法中的错误:.subscribe(res=>this.onResponse(),err=>this.onError())的可能重复您可以处理subscribe方法中的错误:.subscribe(res=>this.onResponse(),err=>this.onError())的可能重复