/// <summary> /// Parse the exception thrown from vault upgrade operations. /// </summary> /// <param name="error">Instance of VaultUpgradeError.</param> /// <returns>Exception message to be shown to customer.</returns> public StringBuilder ParseError( VaultUpgradeError error) { StringBuilder exceptionMessage = new StringBuilder(); if (!string.IsNullOrEmpty(error.Code)) { exceptionMessage.AppendLine("ErrorCode: " + error.Code); } if (!string.IsNullOrEmpty(error.Message)) { exceptionMessage.AppendLine("Message: " + error.Message); } if (!string.IsNullOrEmpty(error.RecommendedAction)) { exceptionMessage.AppendLine("Recommended Action: " + error.RecommendedAction); } return(exceptionMessage.AppendLine(" ")); }
/// <summary> /// Vault upgrade exception handler. /// </summary> /// <param name="ex">Exception to handle.</param> /// <returns>Object to be returned after categorizing all the errors properly /// received as part of vault upgrade operations.</returns> public ExceptionDetails HandleVaultUpgradeException(Exception ex) { ExceptionDetails exceptionDetails = null; string clientRequestIdMsg = string.Empty; if (this.recoveryServicesClient != null) { clientRequestIdMsg = string.Format( Properties.Resources.ClientRequestIdMessage, this.recoveryServicesClient.ClientRequestId, Environment.NewLine); } CloudException cloudException = ex as CloudException; if (cloudException != null) { DataContractSerializer deserializer = null; try { using (Stream stream = new MemoryStream()) { if (cloudException.Error != null && cloudException.Error.OriginalMessage != null) { string message = cloudException.Error.OriginalMessage; byte[] data = System.Text.Encoding.UTF8.GetBytes(message); stream.Write(data, 0, data.Length); stream.Position = 0; if (message.Contains("http://schemas.microsoft.com/wars")) { deserializer = new DataContractSerializer(typeof(StartVaultUpgradeError)); StartVaultUpgradeError error = (StartVaultUpgradeError)deserializer.ReadObject(stream); string msg = string.Format( Properties.Resources.StartVaultUpgradeExceptionDetails, clientRequestIdMsg, error.Message.Value); this.WriteVaultUpgradeError(new InvalidOperationException(msg)); } else { deserializer = new DataContractSerializer(typeof(VaultUpgradeError)); VaultUpgradeError error = (VaultUpgradeError)deserializer.ReadObject(stream); if (error.Details != null) { return this.recoveryServicesClient.ParseErrorDetails(error.Details, clientRequestIdMsg); } else { StringBuilder exceptionMessage = new StringBuilder(); exceptionMessage.AppendLine(Properties.Resources.VaultUpgradeExceptionDetails).AppendLine(" "); exceptionMessage.Append(this.recoveryServicesClient.ParseError(error)); exceptionMessage.AppendLine(clientRequestIdMsg); this.WriteVaultUpgradeError( new InvalidOperationException(exceptionMessage.ToString())); } } } else { throw new Exception( string.Format( Properties.Resources.InvalidCloudExceptionErrorMessage, clientRequestIdMsg + ex.Message), ex); } } } catch (XmlException) { throw new XmlException( string.Format( Properties.Resources.InvalidCloudExceptionErrorMessage, cloudException.Message), cloudException); } catch (SerializationException) { throw new SerializationException( string.Format( Properties.Resources.InvalidCloudExceptionErrorMessage, clientRequestIdMsg + cloudException.Message), cloudException); } } else if (ex.Message != null) { throw new Exception( string.Format( Properties.Resources.InvalidCloudExceptionErrorMessage, clientRequestIdMsg + ex.Message), ex); } return exceptionDetails; }