/// <summary> /// Ends an asynchronous request to an Internet resource. /// </summary> /// <typeparam name="TElement">Element type of the result.</typeparam> /// <param name="source">Source object of async request.</param> /// <param name="context">The data service context.</param> /// <param name="method">async method name.</param> /// <param name="asyncResult">The asyncResult being ended.</param> /// <returns>The response - result of the request.</returns> internal static IEnumerable <TElement> EndExecute <TElement>(object source, DataServiceContext context, string method, IAsyncResult asyncResult) { QueryResult result = null; try { result = QueryResult.EndExecuteQuery <TElement>(source, method, asyncResult); return(result.ProcessResult <TElement>(result.ServiceRequest.Plan)); } catch (DataServiceQueryException ex) { Exception currentInnerException = ex; Exception previousInnerException = null; while (currentInnerException.InnerException != null) { previousInnerException = currentInnerException; currentInnerException = currentInnerException.InnerException; } DataServiceClientException serviceEx = currentInnerException as DataServiceClientException; serviceEx = serviceEx ?? previousInnerException as DataServiceClientException; if (context.IgnoreResourceNotFoundException && serviceEx != null && serviceEx.StatusCode == (int)HttpStatusCode.NotFound) { QueryOperationResponse qor = new QueryOperationResponse <TElement>(ex.Response.HeaderCollection, ex.Response.Query, MaterializeAtom.EmptyResults); qor.StatusCode = (int)HttpStatusCode.NotFound; return((IEnumerable <TElement>)qor); } throw; } }
private static Exception ProcessError(Exception outer, DataServiceClientException inner, IDictionary <string, string> headers) { if (inner == null) { return(null); } using (var writer = WriteToStream(inner.Message)) { var httpMessage = new HttpWebResponseMessage( headers, inner.StatusCode, () => writer.BaseStream); var reader = new ODataMessageReader(httpMessage); try { var error = reader.ReadError(); return(new ODataErrorException(error.Message, outer, error)); } catch { } } return(null); }
/// <summary> /// Translates the data service client exception. /// </summary> /// <param name="e">The exception.</param> /// <returns>The translated exception.</returns> internal static StorageException TranslateDataServiceClientException(Exception e, RequestResult reqResult) { DataServiceClientException dsce = FindInnerExceptionOfType <DataServiceClientException>(e); if (dsce == null) { InvalidOperationException ioe = TableUtilities.FindInnerExceptionOfType <InvalidOperationException>(e); if (ioe != null && !(ioe is WebException) && ioe.Source == "System.Data.Services.Client" && ioe.Message.Contains("type is not compatible with the expected")) { return(new StorageException(reqResult, e.Message, e) { IsRetryable = false }); } return(null); } else { reqResult.ExtendedErrorInformation = StorageExtendedErrorInformation.ReadFromStream(new MemoryStream(Encoding.UTF8.GetBytes(dsce.Message))); reqResult.HttpStatusCode = dsce.StatusCode; return(new StorageException( reqResult, reqResult.ExtendedErrorInformation != null ? reqResult.ExtendedErrorInformation.ErrorCode : dsce.Message, dsce)); } }
public void RetriesWhenDataServiceRequestExceptionIsThrownForServerBusy() { int executeCount = 0; try { var retryPolicy = this.retryManager.GetRetryPolicy <StorageTransientErrorDetectionStrategy>("Retry 5 times"); retryPolicy.ExecuteAction(() => { executeCount++; var innerException = new DataServiceClientException(Microsoft.WindowsAzure.StorageClient.StorageErrorCodeStrings.ServerBusy); var ex = new DataServiceRequestException(Microsoft.WindowsAzure.StorageClient.StorageErrorCodeStrings.ServerBusy, innerException); throw ex; }); Assert.Fail("Should have thrown DataServiceRequestException"); } catch (DataServiceRequestException) { } catch (Exception) { Assert.Fail("Should have thrown DataServiceRequestException"); } Assert.AreEqual(6, executeCount); }
/// <summary> /// Process a <see cref="DataServiceClientException"/> and converts it to a PowerShell /// <see cref="ErrorRecord"/>, or <c>null</c> if that is not availaible. /// </summary> /// <param name="ex">The <see cref="DataServiceClientException"/> that was thrown.</param> private static ErrorRecord AsErrorRecord(this DataServiceClientException ex) { ErrorRecord errorRecord = null; // Attempt to parse OData message or custom web services message try { XElement errorRoot = XElement.Parse(ex.Message); XElement messageElement = errorRoot.Descendants().Where(x => string.Equals(x.Name.LocalName, "Message", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); errorRecord = new ErrorRecord( new CommunicationException(messageElement.Value, ex), string.Empty, ErrorCategory.InvalidOperation, null); } catch (Exception) { // we hide any parsing error that might have happened because there is no need to expose // additional errors } // Return the resulting error record return(errorRecord); }
private ResultSegment <TElement> ParseTableQueryResponse(IEnumerable <TElement> dataServiceQueryResponse, RequestResult reqResult, TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > cmd) { if (reqResult.Exception != null) { DataServiceClientException dsce = TableUtilities.FindInnerExceptionOfType <DataServiceClientException>(reqResult.Exception); if (this.IgnoreResourceNotFoundException && dsce != null && (HttpStatusCode)dsce.StatusCode == HttpStatusCode.NotFound) { return(new ResultSegment <TElement>(new List <TElement>())); } throw reqResult.Exception; } QueryOperationResponse response = dataServiceQueryResponse as QueryOperationResponse; ResultSegment <TElement> retSeg = new ResultSegment <TElement>(dataServiceQueryResponse.ToList()); // Get continuation token from response retSeg.ContinuationToken = TableUtilities.ContinuationFromResponse(response); if (retSeg.ContinuationToken != null) { retSeg.ContinuationToken.TargetLocation = reqResult.TargetLocation; } return(retSeg); }
private static string GetErrorMessage(DataServiceClientException exception, string contentType) { string errorMessage = string.Empty; if (contentType.StartsWith(MimeTypes.ApplicationAtomXml, StringComparison.OrdinalIgnoreCase) || contentType.StartsWith(MimeTypes.ApplicationXml, StringComparison.OrdinalIgnoreCase)) { var xelement = XElement.Parse(exception.Message); var innerError = xelement.Element(xelement.Name.Namespace.GetName("innererror")); if (innerError != null) { errorMessage = innerError.Element(innerError.Name.Namespace.GetName("message")).Value; } else { errorMessage = xelement.Element(xelement.Name.Namespace.GetName("message")).Value; } } else if (contentType.StartsWith(MimeTypes.ApplicationJsonLight, StringComparison.OrdinalIgnoreCase)) { JObject jsonObject = JObject.Parse(exception.Message); var innerError = jsonObject["error"]["innererror"]; if (innerError != null) { errorMessage = ((JValue)innerError["message"]).Value as string; } else { errorMessage = ((JValue)jsonObject["error"]["message"]).Value as string; } } ExceptionUtilities.Assert(!string.IsNullOrEmpty(errorMessage), "Unsupported content type value: " + contentType); return(errorMessage); }
public static Messages ParseMessages(this DataServiceClientException @this) { var message = @this.Message; var messages = message.ParseXML <Messages>(); return(messages); }
public ODataError(Exception ex) { if (ex == null) { throw new ArgumentNullException(); } Type errorType = ex.GetType(); // Awful code if (ex is DataServiceRequestException) { DataServiceRequestException dsre = ex as DataServiceRequestException; this.ProcessDataServiceRequest(dsre); return; } if (ex is DataServiceClientException) { DataServiceClientException dsce = ex as DataServiceClientException; this.ProcessDataServiceClient(dsce); return; } if (ex is DataServiceTransportException) { DataServiceTransportException dste = ex as DataServiceTransportException; this.ProcessDataServiceTransport(dste); return; } if (ex is DataServiceQueryException) { DataServiceQueryException dsqe = ex as DataServiceQueryException; this.ProcessDataServiceQuery(dsqe); return; } if (ex is InvalidOperationException) { InvalidOperationException inoper = ex as InvalidOperationException; this.ProcessInvalidOperation(inoper); return; } if (ex is NotImplementedException) { NotImplementedException notimpl = ex as NotImplementedException; this.ProcessNotImplemented(notimpl); return; } }
/// <summary> /// Indicates whether the specified <see cref="Exception"/> is /// related to an endpoint not being available. /// </summary> /// <param name="exception"></param> /// <returns></returns> public static bool IsEndpointDown(System.Exception exception) { if (exception == null) { throw new ArgumentNullException("exception"); } EndpointNotFoundException endpointNotFoundException = exception as EndpointNotFoundException; if (endpointNotFoundException != null) { return(true); } ServerTooBusyException serverTooBusyException = exception as ServerTooBusyException; if (serverTooBusyException != null) { WebException webException = serverTooBusyException.InnerException as WebException; return(IsEndpointDown(webException)); } TimeoutException timeoutException = exception as TimeoutException; if (timeoutException != null) { return(true); } DataServiceTransportException dataServiceTransportException = exception as DataServiceTransportException; if (dataServiceTransportException != null) { WebException webException = dataServiceTransportException.InnerException as WebException; return(IsEndpointDown(webException)); } DataServiceRequestException dataServiceRequestException = exception as DataServiceRequestException; if (dataServiceRequestException != null) { DataServiceClientException dataServiceClientException = dataServiceRequestException.InnerException as DataServiceClientException; if (dataServiceClientException != null) { WebException webException = dataServiceClientException.InnerException as WebException; return(IsEndpointDown(webException)); } } return(false); }
/// <summary> /// Retrieves the exception details contained in the exception and wrap it in a PowerShell <see cref="ErrorRecord"/>. /// </summary> /// <param name="exception">The exception containing the error details.</param> /// <param name="errorRecord">An output parameter for the error record containing the error details.</param> /// <param name="requestId">An output parameter for the request Id present in the reponse headers.</param> internal static ErrorRecord RetrieveExceptionDetails( Exception exception, out string requestId) { ErrorRecord errorRecord = null; requestId = null; // Look for known exceptions through the exceptions and inner exceptions Exception innerException = exception; while (innerException != null) { CloudException cloudException = innerException as CloudException; if (cloudException != null) { errorRecord = cloudException.AsErrorRecord(out requestId); break; } DataServiceRequestException dataServiceRequestException = innerException as DataServiceRequestException; if (dataServiceRequestException != null) { errorRecord = dataServiceRequestException.AsErrorRecord(); break; } DataServiceClientException dataServiceClientException = innerException as DataServiceClientException; if (dataServiceClientException != null) { errorRecord = dataServiceClientException.AsErrorRecord(); break; } WebException webException = innerException as WebException; if (webException != null) { errorRecord = webException.AsErrorRecord(out requestId); break; } innerException = innerException.InnerException; } // If it's here, it was an unknown exception, wrap the original exception as is. if (errorRecord == null) { errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.NotSpecified, null); } return(errorRecord); }
public void WebRequestTransientErrorDetectionStrategyDataServiceClientExceptionTest() { HttpStatusCode[] allHttpStatusCodeValues = (HttpStatusCode[])Enum.GetValues(typeof(HttpStatusCode)); WebRequestTransientErrorDetectionStrategy strategy = new WebRequestTransientErrorDetectionStrategy(); foreach (HttpStatusCode status in allHttpStatusCodeValues) { DataServiceClientException exception = QueryErrorDetectionStrategyTest.GetMockedClientException(status); Assert.IsFalse(strategy.IsTransient(exception)); } }
private static DataServiceClientException ParseExceptionRecursive(XElement errorElement) { string DataServicesMetadataNamespace = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; XName xnCode = XName.Get("code", DataServicesMetadataNamespace); XName xnType = XName.Get("type", DataServicesMetadataNamespace); XName xnMessage = XName.Get("message", DataServicesMetadataNamespace); XName xnStackTrace = XName.Get("stacktrace", DataServicesMetadataNamespace); XName xnInternalException = XName.Get("internalexception", DataServicesMetadataNamespace); XName xnInnerError = XName.Get("innererror", DataServicesMetadataNamespace); switch (errorElement.Name.LocalName) { case "error": case "innererror": case "internalexception": DataServiceClientException internalException2 = errorElement.Element(xnInternalException) != null? ParseExceptionRecursive(errorElement.Element(xnInternalException)) : null; if (internalException2 != null) { return(internalException2); } DataServiceClientException internalException = errorElement.Element(xnInnerError) != null? ParseExceptionRecursive(errorElement.Element(xnInnerError)) : null; if (internalException != null) { return(internalException); } string code = errorElement.Element(xnCode) != null? errorElement.Element(xnCode).Value.ToString() : String.Empty; string message = errorElement.Element(xnMessage) != null? errorElement.Element(xnMessage).Value.ToString() : String.Empty; string stackTrace = errorElement.Element(xnStackTrace) != null? errorElement.Element(xnStackTrace).Value.ToString() : String.Empty; return(new DataServiceClientException( message, stackTrace, (internalException == null ? internalException2 : internalException) )); default: throw new InvalidOperationException("Could not parse WebException to DataServiceClientException"); } }
public void AzureTableErrorCode_ExtractRestErrorCode_BadData_Null() { string xml = null; var exc = new DataServiceClientException(xml); var strCode = AzureStorageUtils.ExtractRestErrorCode(exc); Assert.IsNull(strCode); var wrapped = new AggregateException(exc); strCode = AzureStorageUtils.ExtractRestErrorCode(wrapped); Assert.IsNull(strCode); }
private static string ExtractMessageFromClientException(Exception exception) { DataServiceQueryException exception2 = exception as DataServiceQueryException; if ((exception2 != null) && (exception2.InnerException != null)) { XDocument document; DataServiceClientException innerException = exception2.InnerException as DataServiceClientException; if ((exception2 != null) && (XmlUtility.TryParseDocument(innerException.Message, out document) && document.Root.Name.LocalName.Equals("error", StringComparison.OrdinalIgnoreCase))) { return(document.Root.GetOptionalElementValue("message", null)); } } return(null); }
public void AzureTableErrorCode_UpdateConditionNotSatisfied() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">" + "<code>UpdateConditionNotSatisfied</code>" + "<message xml:lang=\"en-US\">The update condition specified in the request was not satisfied." + "RequestId:0781ff48-0002-0023-3167-3673bb000000" + "Time:2014-10-29T14:43:17.4073101Z</message>" + "</error>"; var clientExc = new DataServiceClientException(xml); var strCode = AzureStorageUtils.ExtractRestErrorCode(clientExc); Assert.AreEqual(TableErrorCodeStrings.UpdateConditionNotSatisfied, strCode); }
/// <summary> /// Look for an inner exception of type DataServiceClientException. Different versions of Sytem.Data.Services.Client /// have different levels of wrapping of a DataServiceClientException. /// </summary> /// <param name="exception">The exception.</param> /// <returns>The found exception or null.</returns> internal static DataServiceClientException FindInnerDataServiceClientException(Exception exception) { DataServiceClientException dsce = null; while (exception != null) { dsce = exception as DataServiceClientException; if (dsce != null) { break; } exception = exception.InnerException; } return(dsce); }
public void AzureTableErrorCode_ExtractRestErrorCode() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" + "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">" + "<code>OperationTimedOut</code>" + "<message xml:lang=\"en-US\">Operation could not be completed within the specified time. RequestId:6b75e963-c56c-4734-a656-066cfd03f327 Time:2011-10-09T19:33:26.7631923Z</message>" + "</error>"; var exc = new DataServiceClientException(xml); var strCode = AzureStorageUtils.ExtractRestErrorCode(exc); Assert.AreEqual(StorageErrorCodeStrings.OperationTimedOut, strCode); var wrapped = new AggregateException(exc); strCode = AzureStorageUtils.ExtractRestErrorCode(wrapped); Assert.AreEqual(StorageErrorCodeStrings.OperationTimedOut, strCode); }
internal bool HandleException(Exception exception) { Nullable <HttpStatusCode> httpStatusCode = null; DataServiceRequestException requestException = exception as DataServiceRequestException; if (requestException != null) { OperationResponse opResponse = requestException.Response.FirstOrDefault(); httpStatusCode = opResponse != null ? (HttpStatusCode)opResponse.StatusCode : (HttpStatusCode)requestException.Response.BatchStatusCode; } DataServiceClientException clientException = exception as DataServiceClientException; if (!httpStatusCode.HasValue && clientException != null) { httpStatusCode = (HttpStatusCode)clientException.StatusCode; } DataServiceQueryException queryException = exception as DataServiceQueryException; if (!httpStatusCode.HasValue && queryException != null) { httpStatusCode = (HttpStatusCode)queryException.Response.StatusCode; } ODataErrorException odataException = exception as ODataErrorException; if (!httpStatusCode.HasValue && odataException != null) { var _errorCode = odataException.Error; } if (exception is AdalException || exception is ODataErrorException) { return(false); } return(true); }
public void AzureTableErrorCode_ResourceNotFound() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" + "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">" + "<code>ResourceNotFound</code>" + "<message xml:lang=\"en-US\">The specified resource does not exist." + "RequestId:23e7a3b9-3d08-4461-ba49-737c9c211142" + "Time:2013-10-10T17:35:59.7597108Z</message>" + "</error>"; var clientExc = new DataServiceClientException(xml); bool isTableStorageDataNotFound = AzureStorageUtils.TableStorageDataNotFound(clientExc); Assert.IsTrue(isTableStorageDataNotFound, "Is TableStorageDataNotFound " + clientExc); var clientWrapped1 = new AggregateException(clientExc); isTableStorageDataNotFound = AzureStorageUtils.TableStorageDataNotFound(clientWrapped1); Assert.IsTrue(isTableStorageDataNotFound, "Is TableStorageDataNotFound " + clientWrapped1); var clientWrapped2 = new OrleansException("client", clientExc); isTableStorageDataNotFound = AzureStorageUtils.TableStorageDataNotFound(clientWrapped2); Assert.IsTrue(isTableStorageDataNotFound, "Is TableStorageDataNotFound " + clientWrapped2); var clientWrapped3 = new DataServiceQueryException("QueryException", clientExc); isTableStorageDataNotFound = AzureStorageUtils.TableStorageDataNotFound(clientWrapped3); Assert.IsTrue(isTableStorageDataNotFound, "Is TableStorageDataNotFound " + clientWrapped3); var clientWrapped4 = new DataServiceQueryException("Wrapped-clientWrapper1", clientWrapped1); isTableStorageDataNotFound = AzureStorageUtils.TableStorageDataNotFound(clientWrapped4); Assert.IsTrue(isTableStorageDataNotFound, "Is TableStorageDataNotFound " + clientWrapped4); var superWrapped1 = new DataServiceQueryException("SuperWrapped-Client4", new AggregateException("Wrapper5", clientWrapped4)); isTableStorageDataNotFound = AzureStorageUtils.TableStorageDataNotFound(superWrapped1); Assert.IsTrue(isTableStorageDataNotFound, "Is TableStorageDataNotFound " + superWrapped1); }
public void AzureTableErrorCode_ExtractRestErrorCode_InsufficientAccountPermissions() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" + "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">" + "<code>InsufficientAccountPermissions</code>" + "<message xml:lang=\"en-US\">The account being accessed does not have sufficient permissions to execute this operation." + "RequestId:f6f4d0d3-879f-414c-bdf4-582faa7581e8" + "Time:2012-05-14T18:13:13.1526007Z</message>" + "</error>"; var exc = new DataServiceClientException(xml); var strCode = AzureStorageUtils.ExtractRestErrorCode(exc); Assert.AreEqual("InsufficientAccountPermissions", strCode); var wrapped = new AggregateException(exc); strCode = AzureStorageUtils.ExtractRestErrorCode(wrapped); Assert.AreEqual("InsufficientAccountPermissions", strCode); }
public void SaveChangesErrorDetectionStrategyDataServiceClientExceptionTest() { HttpStatusCode[] allHttpStatusCodeValues = (HttpStatusCode[])Enum.GetValues(typeof(HttpStatusCode)); SaveChangesErrorDetectionStrategy strategy = new SaveChangesErrorDetectionStrategy(); foreach (HttpStatusCode status in allHttpStatusCodeValues) { DataServiceClientException exception = QueryErrorDetectionStrategyTest.GetMockedClientException(status); if (strategy.IsTransient(exception)) { Assert.IsTrue(SupportedRetryableHttpStatusCodes.Contains(status), status.ToString()); } else { Assert.IsFalse(SupportedRetryableHttpStatusCodes.Contains(status), status.ToString()); } } }
public void When_DataServiceClientException_is_serialized_all_instance_data_is_saved() { // Arrange const string expectedMessage = "Custom message"; const int expectedStatusCode = 705; var sut = new DataServiceClientException(expectedMessage, expectedStatusCode); var bf = new BinaryFormatter(); var stream = new MemoryStream(); // Act bf.Serialize(stream, sut); stream.Seek(0, SeekOrigin.Begin); var ds = (DataServiceClientException)bf.Deserialize(stream); // Assert Assert.AreEqual(expectedMessage, ds.Message); Assert.AreEqual(expectedStatusCode, ds.StatusCode); }
private static void ReportODataError(DataServiceQueryException ex) { //Client level Exception message Console.WriteLine(ex.Message); //The InnerException of DataServiceQueryException contains DataServiceClientException DataServiceClientException dataServiceClientException = ex.InnerException as DataServiceClientException; // You can get ODataErrorException from dataServiceClientException.InnerException // This object holds Exception as thrown from the service // ODataErrorException contains odataErrorException.Message contains a message string that conforms to dotnet // Exception.Message standards var odataErrorException = dataServiceClientException.InnerException as Microsoft.OData.ODataErrorException; if (odataErrorException != null) { Console.WriteLine(odataErrorException.Message); } Console.WriteLine(dataServiceClientException.Message); }
private void ProcessDataServiceClient(DataServiceClientException dsce) { var new_Ex = dsce.GetBaseException() as Microsoft.OData.Client.DataServiceClientException; string jsonResponse = new_Ex.Message; this.statusCode = new_Ex.StatusCode; switch (this.statusCode) { case HTTP_STATUS_CODE_UNAUTHORIZED: ODataServiceSpringResponse response401 = JsonConvert.DeserializeObject <ODataServiceSpringResponse>(jsonResponse); this.errorMessage = response401.Message; break; default: ODataServiceSdlResponse response = JsonConvert.DeserializeObject <ODataServiceSdlResponse>(jsonResponse); this.errorMessage = response.Error.Message; break; } }
/// <summary> /// execute uri and materialize result /// </summary> /// <typeparam name="TElement">element type</typeparam> /// <param name="context">context</param> /// <param name="queryComponents">query components for request to execute</param> /// <returns>enumerable of results</returns> internal QueryOperationResponse <TElement> Execute <TElement>(DataServiceContext context, QueryComponents queryComponents) { QueryResult result = null; try { Uri requestUri = queryComponents.Uri; DataServiceRequest <TElement> serviceRequest = new DataServiceRequest <TElement>(requestUri, queryComponents, this.Plan); result = serviceRequest.CreateExecuteResult(this, context, null, null, Util.ExecuteMethodName); result.ExecuteQuery(); return(result.ProcessResult <TElement>(this.Plan)); } catch (InvalidOperationException ex) { if (result != null) { QueryOperationResponse operationResponse = result.GetResponse <TElement>(MaterializeAtom.EmptyResults); if (operationResponse != null) { if (context.IgnoreResourceNotFoundException) { DataServiceClientException cex = ex as DataServiceClientException; if (cex != null && cex.StatusCode == (int)HttpStatusCode.NotFound) { // don't throw return((QueryOperationResponse <TElement>)operationResponse); } } operationResponse.Error = ex; throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse); } } throw; } }
public void AzureTableErrorCode_ExtractRestErrorCode_ServerBusy() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" + "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">" + "<code>ServerBusy</code>" + "<message xml:lang=\"en-US\">The server is busy." + "RequestId:14ab4de6-fe80-4a45-a364-b0c2a27a4a86" + "Time:2013-09-24T23:29:13.4913945Z</message>" + "</error>"; var exc = new DataServiceClientException(xml); var strCode = AzureStorageUtils.ExtractRestErrorCode(exc); Assert.AreEqual(StorageErrorCodeStrings.ServerBusy, strCode); var wrapped = new AggregateException(exc); strCode = AzureStorageUtils.ExtractRestErrorCode(wrapped); Assert.AreEqual(StorageErrorCodeStrings.ServerBusy, strCode); //Assert.IsTrue(Async_AzureTableDataManager<SiloMetricsData>.IsRetriableHttpError((HttpStatusCode)500, "ServerBusy")); }
/// <summary> /// Gets the result or default. /// </summary> /// <typeparam name="T">The type of the result.</typeparam> /// <param name="task">The task to retrieve the result from.</param> /// <param name="result">Receives result of the task.</param> /// <returns><c>true</c> if the result was returned; otherwise, <c>false</c>.</returns> private static bool GetResultOrDefault <T>(Task <T> task, out T result) { try { result = task.Result; return(true); } catch (DataServiceQueryException ex) { if ((HttpStatusCode)ex.Response.StatusCode == HttpStatusCode.NotFound) { result = default(T); return(false); } throw Utilities.TranslateDataServiceClientException(ex); } catch (InvalidOperationException ex) { DataServiceClientException dsce = CommonUtils.FindInnerDataServiceClientException(ex); if (dsce != null) { if ((HttpStatusCode)dsce.StatusCode == HttpStatusCode.NotFound) { result = default(T); return(false); } } throw Utilities.TranslateDataServiceClientException(ex); } }
private static string GetExceptionMessage(Exception exception) { HttpStatusCode statusCode; StorageExtendedErrorInformation extendedErrorInfo; if (TableStorageHelpers.EvaluateException(exception, out statusCode, out extendedErrorInfo)) { if (extendedErrorInfo != null) { return(string.Format(CultureInfo.InvariantCulture, "{0} {1}", extendedErrorInfo.ErrorCode ?? "", extendedErrorInfo.ErrorMessage ?? "")); } } DataServiceClientException dse = exception.InnerException as DataServiceClientException; if (dse != null) { return(dse.Message); } else { return(exception.Message); } }
protected override bool CheckIsTransient(Exception ex) { if (IsRetriableWebException(ex, operationIdempotentOnRetry: true, retryOnUnauthorizedErrors: true)) { return(true); } DataServiceRequestException dataServiceException = ex as DataServiceRequestException; if (dataServiceException != null) { if (IsErrorStringMatch(GetErrorCode(dataServiceException), StorageErrorCodeStrings.InternalError, StorageErrorCodeStrings.ServerBusy, StorageErrorCodeStrings.OperationTimedOut, TableErrorCodeStrings.TableServerOutOfMemory)) { return(true); } } DataServiceQueryException dataServiceQueryException = ex as DataServiceQueryException; if (dataServiceQueryException != null) { if (IsErrorStringMatch(GetErrorCode(dataServiceQueryException), StorageErrorCodeStrings.InternalError, StorageErrorCodeStrings.ServerBusy, StorageErrorCodeStrings.OperationTimedOut, TableErrorCodeStrings.TableServerOutOfMemory)) { return(true); } } DataServiceClientException dataServiceClientException = ex.FindInnerException <DataServiceClientException>(); if (dataServiceClientException != null) { if (IsRetriableHttpStatusCode(dataServiceClientException.StatusCode, operationIdempotentOnRetry: true, retryOnUnauthorizedErrors: true)) { return(true); } if (IsErrorStringMatch(dataServiceClientException.Message, StorageErrorCodeStrings.InternalError, StorageErrorCodeStrings.ServerBusy, StorageErrorCodeStrings.OperationTimedOut, TableErrorCodeStrings.TableServerOutOfMemory)) { return(true); } } var serverException = ex as StorageException; if (serverException != null) { if (IsErrorStringMatch(serverException, StorageErrorCodeStrings.InternalError, StorageErrorCodeStrings.ServerBusy, StorageErrorCodeStrings.OperationTimedOut, TableErrorCodeStrings.TableServerOutOfMemory)) { return(true); } } if (IsTimeoutException(ex)) { return(true); } if (IsSocketException(ex)) { return(true); } if ((ex.FindInnerException <IOException>() != null) && !(ex is FileLoadException)) { return(true); } return(false); }