Aurelia 奥雷利亚拦截器法
如何打破承诺链并转到捕获方法,在我的代码下面:Aurelia 奥雷利亚拦截器法,aurelia,fetch-api,Aurelia,Fetch Api,如何打破承诺链并转到捕获方法,在我的代码下面: .withInterceptor({ response(response,d) { console.log(`Received ${response.status} ${response.url}`); // Catch if(!response.ok){ return response.json().then(err => { t
.withInterceptor({
response(response,d) {
console.log(`Received ${response.status} ${response.url}`);
// Catch
if(!response.ok){
return response.json().then(err => {
throw new Error(err.faultMessage);
});
}
return response.json();
}
});
get(url: String, object: Object = {}) {
let promise = this.httpClient.fetch(`${url}?${$.param(object)}`, {
method: 'GET'
}).catch(e=>this.catchError(e));
return promise;
}
catchError(msg){
this.notifySrvc.notify(msg,'error');
}
从另一个地方,我称此get方法为:
srvc.get('url',{}).then(function(res){console.log(res)})
发生的事情是,然后被调用,同时捕获如何改变这种奇怪的行为?据我所知,你不能用拦截器打破承诺链。您可以检查响应的内容,但不能截取或编辑它。我去年在Aurelia API Repo上创建了一个关于Aurelia Fetch拦截器缺点的应用程序。我想这涵盖了您所说的内容?谢谢您的回复,我通过使用promise对象找到了另一个解决方案,并且基于fetch api响应(如果确定或不确定),我解析或拒绝了请求。