public static Task <TResult> ResolveCreate <TResult>(this StorageException exception, Microsoft.WindowsAzure.Storage.Table.CloudTable table, Func <TResult> retry, Func <ExtendedErrorInformationCodes, string, TResult> onFailure = default, Func <TResult> onAlreadyExists = default, AzureStorageDriver.RetryDelegate onTimeout = default) { return(exception.ParseStorageException( onEntityAlreadyExists: (msg) => onAlreadyExists().AsTask(), onNotFound: async(msg) => // IsProblemTableDoesNotExist { try { await table.CreateIfNotExistsAsync(); return retry(); } catch (StorageException createEx) { // Catch bug with azure storage table client library where // if two resources attempt to create the table at the same // time one gets a precondtion failed error. System.Threading.Thread.Sleep(1000); return retry(); } catch (Exception) { throw; }; }, onTimeout: async(msg) => // IsProblemTimeout { if (onTimeout.IsDefaultOrNull()) { onTimeout = AzureStorageDriver.GetRetryDelegate(); } bool shouldRetry = false; await onTimeout(exception.RequestInformation.HttpStatusCode, exception, () => { shouldRetry = true; return 1.AsTask(); }); if (shouldRetry) { return retry(); } throw exception; }, onDefaultCallback: (error, msg) => onFailure(error, msg).AsTask())); }