Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean way to catch errors from Azure Table (other than string match?)

I'd like to get a list of all the Azure Table errors and figure out a clean way to handle them in a try...catch block.

For example, I'd like to not have to directly code and compare the InnerException message to String.Contains("The specified entity already exists"). What is the right way to trap these errors?

alt text

like image 638
makerofthings7 Avatar asked Jan 21 '23 10:01

makerofthings7


1 Answers

You could try looking at the values in the Response, rather that the inner exception. This is an example of one of my try catch blocks:

try {
    return query.FirstOrDefault();
}
catch (System.Data.Services.Client.DataServiceQueryException ex)
{
    if (ex.Response.StatusCode == (int)System.Net.HttpStatusCode.NotFound) {
        return null;
    }
    throw;
}

Obviously this is just for the item doesn't exist error, but I'm sure you can expand on this concept by looking at the list of Azure error codes.

like image 135
knightpfhor Avatar answered May 11 '23 17:05

knightpfhor