public void SqlDatabaseManagementErrorTest() { string serverRequestId = Guid.NewGuid().ToString(); string errorMessage = @"<Error xmlns=""http://schemas.microsoft.com/sqlazure/2010/12/""> <Code>40647</Code> <Message>Subscription '00000000-1111-2222-3333-444444444444' does not have the server 'server0001'.</Message> <Severity>16</Severity> <State>1</State> </Error>"; WebException exception = CreateWebException(HttpStatusCode.BadRequest, errorMessage, (context) => { context.Response.Headers.Add(Constants.RequestIdHeaderName, serverRequestId); }); ErrorRecord errorRecord; string requestId; SqlDatabaseManagementHelper.RetrieveExceptionDetails(exception, out errorRecord, out requestId); Assert.AreEqual(serverRequestId, requestId); Assert.AreEqual( @"Subscription '00000000-1111-2222-3333-444444444444' does not have the server 'server0001'. Error Code: 40647", errorRecord.Exception.Message); }
public void ServiceResourceErrorTest() { string serverRequestId = Guid.NewGuid().ToString(); string errorMessage = @"<Error xmlns=""Microsoft.SqlServer.Management.Framework.Web.Services"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><Message>Resource with the name 'FirewallRule1' does not exist. To continue, specify a valid resource name.</Message><InnerError i:nil=""true""/></Error>"; WebException exception = CreateWebException(HttpStatusCode.NotFound, errorMessage, (context) => { context.Response.Headers.Add(Constants.RequestIdHeaderName, serverRequestId); }); ErrorRecord errorRecord; string requestId; SqlDatabaseManagementHelper.RetrieveExceptionDetails(exception, out errorRecord, out requestId); Assert.AreEqual(serverRequestId, requestId); Assert.AreEqual("Resource with the name 'FirewallRule1' does not exist. To continue, specify a valid resource name.", errorRecord.Exception.Message); }
protected override void WriteErrorDetails(CommunicationException exception) { string requestId; ErrorRecord errorRecord; SqlDatabaseManagementHelper.RetrieveExceptionDetails(exception, out errorRecord, out requestId); // Write the request Id as a warning if (requestId != null) { // requestId was availiable from the server response, write that as warning to the console WriteWarning(string.Format(CultureInfo.InvariantCulture, Resources.ExceptionRequestId, requestId)); } else { // requestId was not availiable from the server response, write the client Ids that was sent WriteWarning(string.Format(CultureInfo.InvariantCulture, Resources.ExceptionClientSessionId, SqlDatabaseManagementCmdletBase.clientSessionId)); WriteWarning(string.Format(CultureInfo.InvariantCulture, Resources.ExceptionClientRequestId, this.clientRequestId)); } // Write the actual errorRecord containing the exception details WriteError(errorRecord); }