删除存储数据时,如果数据使用deleteObject(Storageref)时是否存在错误?

发布于 2025-02-07 19:46:35 字数 394 浏览 1 评论 0原文

我正在创建删除用户数据功能。此功能的一部分是清洁存储。 如果用户一开始没有映像,则会生成错误,以停止其余功能的例外,如何防止此错误形式发生,而无需检查并提出get请求以查看是否有数据在存储中开始?

错误信息 : 对象“配置文件/ID”不存在。 (存储/对象 - 未找到)

// Delete user's Storage Data
const storage = getStorage();
const storageRef = ref(storage, `profiles/${currentUser.uid}`);
await deleteObject(storageRef);
// Delete the user 
await deleteUser(currentUser);

I am creating a delete user data function. One part of this function is to clean storage.
If the user don't have an image to begin with, an error is generated halting the exception of the rest of the function, how to prevent this error form happening, without having to check and make a get request to see if there is data in storage to begin with ?

Error message :
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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秉烛思 2025-02-14 19:46:35

如@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);

您可以参考此对于其他可用错误消息。

As mentioned by @JohnHanley, you can use exception handling and catch the error.

See sample code below on how to implement exception handling:

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);

You can refer to this documentation for other available error messages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文