我正在創建洗掉用戶資料功能。此功能的一部分是清潔存盤。如果用戶沒有影像開始,則會產生錯誤,停止其余功能的例外,如何防止這種錯誤形式發生,而無需檢查并發出get請求以查看是否有資料在存盤開始?
錯誤資訊 :
Object 'profiles/id' does not exist. (storage/object-not-found)
// Delete user's Storage Data
const storage = getStorage();
const storageRef = ref(storage, `profiles/${currentUser.uid}`);
await deleteObject(storageRef);
// Delete the user
await deleteUser(currentUser);
uj5u.com熱心網友回復:
正如@JohnHanley 所提到的,您可以使用例外處理并捕獲錯誤。
有關如何實作例外處理,請參見下面的示例代碼:
const storage = getStorage();
const storageRef = ref(storage, `profiles/${currentUser.uid}`);
await deleteObject(storageRef).then(() => {
console.log("File deleted successfully!")
}).catch((error) => {
// Do something if error occured.
if (error.code == 'storage/object-not-found') {
console.log('Object not found!')
}
});
// Delete the user
await deleteUser(currentUser);
您可以參考此檔案以了解其他可用的錯誤訊息。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491976.html
標籤:火力基地 谷歌云存储 firebase-存储
