Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
error when deleting storage data if data don't exists when using deleteObject(storageRef)?

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);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!