2015-05-04 39 views
1

有什麼方法可以避免控制檯上的permission_denied異常轉儲。我不想在控制檯上看到這個異常,並想優雅地處理它。我試過follownig,但它似乎並沒有工作。我也嘗試過.onAuth(),但這也不能阻止這種情況的發生。如何處理Firebase權限正常拒絕異常

var ref = new Firebase(<My firebase root url>), 
ref.on("value", function(snapshot) { 
    console.log("No errors."); 
}, function(err) { 
    console.log("Something is wrong. "+err); 
}); 

Something is wrong. Error: permission_denied: Client doesn't have permission to access the desired data. 
SearchCtrl.js:22 User Not Authenticated..Redirecting to Sign In Page... 
ionic.bundle.js:19532 Error: permission_denied: Client doesn't have permission to access the desired data. 
    at Error (native) 
    at J (http://localhost:8100/lib/firebase/firebase.js:120:48) 
    at Object.J (http://localhost:8100/lib/firebase/firebase.js:200:378) 
    at http://localhost:8100/lib/firebase/firebase.js:185:3 
    at vh.h.Hd (http://localhost:8100/lib/firebase/firebase.js:189:104) 
    at jh.Hd (http://localhost:8100/lib/firebase/firebase.js:180:364) 
    at bh.jh.Da.uh.t [as tg] (http://localhost:8100/lib/firebase/firebase.js:178:281) 
    at eh (http://localhost:8100/lib/firebase/firebase.js:172:464) 
    at WebSocket.bh.open.va.onmessage (http://localhost:8100/lib/firebase/firebase.js:171:245)(anonymous function) @ ionic.bundle.js:19532c.$$error @ angularfire.min.js:12(anonymous function) @ angularfire.min.js:12(anonymous function) @ angularfire.min.js:12forEach @ ionic.bundle.js:8248g @ angularfire.min.js:12(anonymous function) @ ionic.bundle.js:24148completeOutstandingRequest @ ionic.bundle.js:12830(anonymous function) @ ionic.bundle.js:
ionic.bundle.js:19532 destroy called for FirebaseArray: https://fixmycars.firebaseio.com/customers 
ionic.bundle.js:19532 TypeError: Cannot read property '$$error' of null 
    at angularfire.min.js:12 
    at angularfire.min.js:12 
    at Object.forEach (ionic.bundle.js:8248) 
    at g (angularfire.min.js:12) 
    at ionic.bundle.js:24148 
    at completeOutstandingRequest (ionic.bundle.js:12830) 
    at ionic.bundle.js:(anonymous function) @ ionic.bundle.js:19532$get @ ionic.bundle.js:16482(anonymous function) @ ionic.bundle.js:24151completeOutstandingRequest @ ionic.bundle.js:12830(anonymous function) @ ionic.bundle.js:
+0

這裏的正確答案通常是在訪問數據之前確保用戶具有正確的權限。在大多數情況下,如果客戶端嘗試訪問數據而沒有權限,則可以將其視爲錯誤。由於您將錯誤記錄到控制檯,因此刪除錯誤消息的日誌似乎非常簡單。此外,[指南](https://www.firebase.com/docs/web/guide/)的良好通讀將會爲您節省,堆棧溢出會導致很多抖動。 – Kato

+0

這個異常不是因爲我試圖顯示的錯誤對象。我甚至嘗試刪除該對象,我仍然可以看到該異常。在該行執行後,只需在firebase.js和ionic-bundle.js中來回切換,最後從ionic-bundle.js中返回異常的「self.defer」方法。 – ATHER

+0

看起來像您有一個[XY問題](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378)。 – Kato

回答

0

似乎你自己在控制檯上添加permission_denied異常轉儲。 請勿將控制檯日誌中的「err」添加到錯誤處理函數 (例如, console.log(「有問題。」+ err);

+0

這個異常並不是因爲我試圖顯示的err對象。我甚至嘗試刪除該對象,我仍然可以看到該異常。在該行執行之後,只需在firebase.js和ionic-bundle.js中來回切換,最後從ionic-bundle.js中調用引發該異常的「self.defer」方法。 – ATHER

1

解析錯誤和/或創建一個匹配規則來處理您想要處理的所有錯誤。將處理程序放置在當前結構的else語句中。

var ref = new Firebase(<My firebase root url>), 
ref.on("value", function(snapshot) { 
    if(snapshot.exists()){ 
     /*Update dom or kick of async method to mount snapshot*/ 
    }else{ 
     app.$.errorToast.text = 'Snapshot does not exist'; 
     app.$.errorToast.show(); 
    } 
    console.log("Did I forget to handle an error"); 
}, function(err) { 
    /*Compare "err" to your rules and handle as needed here*/ 
    console.log("Something is wrong. "+err); 
}); 

你在哪裏都在你的代碼中嘗試完成未允許性的「對」功能將火和處理作爲單一代碼塊上述定義的動作。

爲客戶端提供良好的解析消息,例如「當前用戶不被允許訪問,獲得訪問權限聯繫管理員並請求將用戶ID添加到權限組{myRefMeta.permgroup}」。我考慮的一個選擇是維護另一個描述權限的分支,或者在提供安全細節的基節點中添加一個公共可訪問的「分支描述符」。用戶的這方面的知識以及與您一起工作的樹的描述符將能夠在發生錯誤之前消除此錯誤。

在用戶註銷並緩存不被清除你的ref.on事件將再次觸發的情況。發生這種情況時,應注意清除緩存並完成完整的重新加載。這可以通過在清除緩存後強制刷新瀏覽器來實現。

在誤差超過該代碼塊在ref.on被處理和ref.on不會到達呼叫重新安裝快照或更新DOM。通過在錯誤處理程序中調用清理方法,您可以掛載一個空快照,重置參考並禁用不可用的功能。

這是最適合我的目的,等到需要的權限從用戶,並通過創建一個方便的功能「referenceCheck」您可以使用此需要揭開序幕驗證和基準製作提出要求。這將作爲「usecase」的初始化方法,並且該用例的清理將對此非常有用。

相關問題