Search code examples
javascriptazureazure-files

Are there multiple reasons for Azure error: "The specified resource does not exist"?


I have a project with tons of users and their uploaded files. The database has all files available, but around a year ago, when connecting the project to Azure and migrating the files, some files were forgotten in the process. While the code now uploads files automatically to Azure when uploading them to database, trying to delete some older files cause issues.

Currently my code checks Azure deletion first and then decides on deleting the file from the database. When trying to delete a file, that doesn't exist in Azure, I get the error message:

StorageError: The specified resource does not exist.

This means, that the current logic doesn't delete it from the database either. I can always just ignore the error from Azure and delete it regardless, but I don't know what would be the best and safest way to do it.

Easiest would probably be to either delete the file anyways

if (!error) { 
    deleteFile(); 
} else {
    console.log("Azure failed, deleting anyways", error);
    deleteFile();
}

or delete it only, if the error is the one aforementioned.

if (!error) { 
    deleteFile(); 
} else if (error.message === "The specified resource does not exist") {
    console.log("Resource doesn't exist, deleting anyways", error);
    deleteFile();
}

But I don't know enough about the error message. Is there another reason to get the same error message and a possibility to delete a file in a wrong situation? Or are there other reasons this shouldn't be done? I've searched the web using the error message, but found many posts regarding permissions, so could this lead to any security problems?


Solution

  • There are 2 possible reasons when you can get StorageError: The specified resource does not exist.:

    1. Blob does not exist and
    2. Blob container for that blob does not exist.

    If you are not able to delete a blob for any other reasons (e.g. incorrect authorization, blob is leased etc.), you will get a different error message.