public static ParsedException ParseException(Exception ex) { Exception innerException = ex.InnerException; ParsedException parsedException = null; if (innerException != null) { try { XDocument xDoc = XDocument.Parse(innerException.Message); parsedException = new ParsedException(); var xElement = xDoc.Root.Element(xnMessage); if (xElement != null) { parsedException.Message = xDoc.Root != null && xElement != null? xElement.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; } var element = xDoc.Root.Element(xnCode); if (element != null) { parsedException.Code = element != null? element.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; } if (xDoc.Root.Element(xnInnerError) != null) { XElement innerError = xDoc.Root.Element(xnInnerError); parsedException.InnerErrorExists = true; var xElement1 = innerError.Element(xnMessage); if (xElement1 != null) { parsedException.InnerErrorMessage = innerError != null && xElement1 != null? xElement1.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; } var element1 = innerError.Element(xnCode); if (element1 != null) { parsedException.InnerErrorCode = element1 != null? element1.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; } } } catch { throw new Exception("Generic DataService Exception", ex); } } return(parsedException); }
public static ParsedException ParseException(Exception ex) { Exception innerException = ex.InnerException; ParsedException parsedException = null; if (innerException != null) { try { XDocument xDoc = XDocument.Parse(innerException.Message); parsedException = new ParsedException(); var xElement = xDoc.Root.Element(xnMessage); if (xElement != null) parsedException.Message = xDoc.Root != null && xElement != null ? xElement.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; var element = xDoc.Root.Element(xnCode); if (element != null) parsedException.Code = element != null ? element.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; if (xDoc.Root.Element(xnInnerError) != null) { XElement innerError = xDoc.Root.Element(xnInnerError); parsedException.InnerErrorExists = true; var xElement1 = innerError.Element(xnMessage); if (xElement1 != null) parsedException.InnerErrorMessage = innerError != null && xElement1 != null ? xElement1.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; var element1 = innerError.Element(xnCode); if (element1 != null) parsedException.InnerErrorCode = element1 != null ? element1.Value.ToString(CultureInfo.InvariantCulture) : String.Empty; } } catch { throw new Exception("Generic DataService Exception", ex); } } return parsedException; }
/// <summary> /// Delegate for invoking networking operations with retry. /// </summary> /// <param name="operation"></param> private void InvokeOperationWithRetry(Action operation) { try { operation(); } catch (Exception ex) { ParsedException parsedException = DataServiceExceptionUtil.ParseException(ex); if (parsedException == null) { throw; } else { switch (parsedException.Code) { case "Authentication_ExpiredToken": case "Authentication_Unauthorized": case "Authentication_Unknown": case "Authentication_UnsupportedTokenType": case "Headers_DataContractVersionMissing": case "Headers_HeaderNotSupported": case "Service_InternalServerError": case "Directory_CompanyNotFound": case "Request_ThrorttledPermanently": case "Unsupported_Query": case "": { throw parsedException; } case "Directory_BindingRedirection": break; case "Directory_ReplicaUnavailable": break; case "Request_InvalidReplicaSessionKey": break; case "Request_ThrorttledTemporarily": break; } } } }