[英]I can't catch specific browser logged errors from an AJAX call. Is catching these even possible?
[英]Can't catch errors from ember backgroundReload
假設我們有一個UsersIndexRoute
,我們在其中加載所有用戶。
model() {
return this.store.findAll('users');
}
當我們第一次加載頁面(硬重新加載)並收到HTTP 500 error
我們在ApplicationRoute
的errors()
收到此錯誤,並且可以呈現錯誤頁面,一切都很好。
但是:假設我們已經加載了Ember App,但是只加載了一部分用戶,請轉到/users
頁面並再次調用findAll
,Ember立即返回我們已經加載到商店中的用戶子集,並提取所有其他用戶用戶在后台請求。
現在在我們的情況下,我們在backgroundReload中返回了HTTP 500 error
,但看起來像https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store.js#L1027不會返回promise數組,並且我們無法再在findAll
方法中捕獲錯誤,或者在ApplicationRoute
的error()
接收任何錯誤。
我的問題是:如何以及在哪里可以從backgroundReload中捕獲錯誤?
您可以使用.then()
方法捕獲任何錯誤:
model() {
return this.store.findAll('users')
.then(null, (error) => {/*do smth*/});
}
這是GH問題,討論了該主題,並給出了該問題的“解決方案”: https : //github.com/emberjs/data/issues/3809
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.