public static bool IsProblemTimeout(this global::Azure.RequestFailedException exception) { if (exception.InnerException is System.Net.WebException) { var webEx = (System.Net.WebException)exception.InnerException; return(webEx.Status == System.Net.WebExceptionStatus.Timeout); } if (408 == (int)exception.GetHttpStatusCode()) // RequestInformation.HttpStatusCode) { return(true); } return(false); }
public static bool IsProblemDoesNotExist(this global::Azure.RequestFailedException exception) { return(exception.ParseExtendedErrorInformation( (errorCode, message) => { if (errorCode == ExtendedErrorInformationCodes.TableNotFound) { return true; } if (errorCode == ExtendedErrorInformationCodes.BlobNotFound) { return true; } if (errorCode == ExtendedErrorInformationCodes.Other) { if ("ContainerNotFound".Equals(exception.ErrorCode, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; }, () => { if (exception.GetHttpStatusCode() == HttpStatusCode.NotFound) { return true; } if (exception.InnerException is System.Net.WebException) { var webEx = (System.Net.WebException)exception.InnerException; if (webEx.Response is System.Net.HttpWebResponse) { var httpResponse = (System.Net.HttpWebResponse)webEx.Response; return (httpResponse.StatusCode == System.Net.HttpStatusCode.NotFound); } } return false; })); }
public static Task <TResult> ResolveCreate <TResult>(this global::Azure.RequestFailedException exception, CloudTable table, Func <TResult> retry, Func <ExtendedErrorInformationCodes, string, TResult> onFailure = default, Func <TResult> onAlreadyExists = default, AzureStorageDriver.RetryDelegate onTimeout = default) { return(exception.ParseStorageException( onEntityAlreadyExists: (msg) => { if (!onAlreadyExists.IsDefaultOrNull()) { return onAlreadyExists().AsTask(); } throw new ExtendedErrorInformationException(ExtendedErrorInformationCodes.EntityAlreadyExists, msg); }, onNotFound: async(msg) => // IsProblemTableDoesNotExist { try { await table.CreateIfNotExistsAsync(); return retry(); } catch (global::Azure.RequestFailedException 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((int)exception.GetHttpStatusCode(), exception, () => { shouldRetry = true; return 1.AsTask(); }); if (shouldRetry) { return retry(); } throw exception; }, onDefaultCallback: (error, msg) => { if (!onFailure.IsDefaultOrNull()) { return onFailure(error, msg).AsTask(); } throw new ExtendedErrorInformationException(error, msg); })); }