/// <summary> /// Parses the error response into an exception. /// </summary> /// <param name="errors">The error response from the server.</param> /// <returns></returns> private ReportsException ParseException(string errorsXml) { XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(errorsXml); XmlNodeList errorNodes = xDoc.DocumentElement.SelectNodes("ApiError"); List <ReportDownloadError> errorList = new List <ReportDownloadError>(); foreach (XmlElement errorNode in errorNodes) { ReportDownloadError downloadError = new ReportDownloadError(); downloadError.ErrorType = errorNode.SelectSingleNode("type").InnerText; downloadError.FieldPath = errorNode.SelectSingleNode("fieldPath").InnerText; downloadError.Trigger = errorNode.SelectSingleNode("trigger").InnerText; errorList.Add(downloadError); } ReportsException ex = new ReportsException("Report download errors occurred, see errors " + "field for more details."); ex.Errors = errorList.ToArray(); return(ex); }
/// <summary> /// Determines whether the exception thrown by the server matches a known /// error. /// </summary> /// <param name="ex">The exception.</param> /// <param name="errorMessage">The known error message.</param> /// <returns>True, if the server exception matches the known error, false /// otherwise.</returns> private static bool MatchesError(ReportsException ex, string[] errorMessages) { foreach (ReportDownloadError error in ex.Errors) { foreach (String errorMessage in errorMessages) { if (error.ErrorType.Contains(errorMessage)) { return true; } } } return false; }