From 7bb4164e043ec54531d0ba4e80db5c1105143eef Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Thu, 20 Apr 2023 22:40:10 -0700 Subject: [PATCH 01/16] Add Response property to RequestFailedException --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 1 + sdk/core/Azure.Core/api/Azure.Core.net5.0.cs | 1 + sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 1 + .../api/Azure.Core.netcoreapp2.1.cs | 1 + .../api/Azure.Core.netstandard2.0.cs | 1 + .../Azure.Core/src/RequestFailedException.cs | 51 ++++++++-------- .../tests/FailedResponseExceptionTests.cs | 59 +++++++++++++++++-- 7 files changed, 83 insertions(+), 32 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 4ccc966869bb5..54606f45ad53e 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -223,6 +223,7 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } + public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs index 0d35cd47af870..710ef33d893da 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs @@ -223,6 +223,7 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } + public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index 0d35cd47af870..710ef33d893da 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -223,6 +223,7 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } + public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs index 4ccc966869bb5..54606f45ad53e 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs @@ -223,6 +223,7 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } + public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 4ccc966869bb5..54606f45ad53e 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -223,6 +223,7 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } + public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } } diff --git a/sdk/core/Azure.Core/src/RequestFailedException.cs b/sdk/core/Azure.Core/src/RequestFailedException.cs index fcbf1f24ce793..0a81bf8803632 100644 --- a/sdk/core/Azure.Core/src/RequestFailedException.cs +++ b/sdk/core/Azure.Core/src/RequestFailedException.cs @@ -31,6 +31,11 @@ public class RequestFailedException : Exception, ISerializable /// public string? ErrorCode { get; } + /// + /// Gets the response, if any, that led to the exception. + /// + public Response? Response { get; } + /// Initializes a new instance of the class with a specified error message. /// The message that describes the error. public RequestFailedException(string message) : this(0, message) @@ -105,6 +110,7 @@ public RequestFailedException(Response response) public RequestFailedException(Response response, Exception? innerException) : this(response.Status, GetRequestFailedExceptionContent(response), innerException) { + Response = response; } /// @@ -128,6 +134,8 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont internal static (string FormattedError, string? ErrorCode, IDictionary? Data) GetRequestFailedExceptionContent(Response response) { + BufferResponseIfNeeded(response); + bool parseSuccess = response.RequestFailedDetailsParser == null ? TryExtractErrorContent(response, out ResponseError? error, out IDictionary? data) : response.RequestFailedDetailsParser.TryParse(response, out error, out data); StringBuilder messageBuilder = new(); @@ -191,25 +199,23 @@ internal static (string FormattedError, string? ErrorCode, IDictionary - /// This is intentionally sync-only as it will only be called by the ctor. - /// - /// - /// - internal static string? ReadContent(Response response) + private static void BufferResponseIfNeeded(Response response) { - string? content = null; - - if (response.ContentStream != null && - ContentTypeUtilities.TryGetTextEncoding(response.Headers.ContentType, out var encoding)) + // Buffer into a memory stream if not already buffered + if (response.ContentStream is null or MemoryStream) { - using (var streamReader = new StreamReader(response.ContentStream, encoding)) - { - content = streamReader.ReadToEnd(); - } + return; } - return content; + var bufferedStream = new MemoryStream(); + response.ContentStream.CopyTo(bufferedStream); + + // Dispose the unbuffered stream + response.ContentStream.Dispose(); + + // Reset the position of the buffered stream and set it on the response + bufferedStream.Position = 0; + response.ContentStream = bufferedStream; } internal static bool TryExtractErrorContent(Response response, out ResponseError? error, out IDictionary? data) @@ -218,18 +224,9 @@ internal static bool TryExtractErrorContent(Response response, out ResponseError data = null; try { - string? content = null; - if (response.ContentStream != null && response.ContentStream.CanSeek) - { - content = response.Content.ToString(); - } - else - { - // this path should only happen in exceptional cases such as when - // the RFE ctor was called directly by client or customer code with an un-buffered response. - // Generated code would never do this. - content = ReadContent(response); - } + // The response content is buffered at this point. + string? content = response.Content.ToString(); + // Optimistic check for JSON object we expect if (content == null || !content.StartsWith("{", StringComparison.OrdinalIgnoreCase)) { diff --git a/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs b/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs index af6e3aa5bd86c..d0a7092be66af 100644 --- a/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs +++ b/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs @@ -40,6 +40,12 @@ public async Task FormatsResponse() RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); Assert.AreEqual(formattedResponse, exception.Message); + + Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); + Assert.AreEqual("Value", value); + Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.AreEqual("123", requestId); + Assert.IsNull(exception.Response.ContentStream); } [Test] @@ -60,6 +66,12 @@ public void FormatsResponse_ResponseCtor() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); + + Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); + Assert.AreEqual("Value", value); + Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.AreEqual("123", requestId); + Assert.IsNull(exception.Response.ContentStream); } [Test] @@ -79,6 +91,12 @@ public void FormatsResponseWithoutSanitizer_ResponseCtor() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); + + Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); + Assert.AreEqual("Value", value); + Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.AreEqual("123", requestId); + Assert.IsNull(exception.Response.ContentStream); } [Test] @@ -141,6 +159,14 @@ public async Task FormatsResponseContentForTextContentTypes() RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); Assert.AreEqual(formattedResponse, exception.Message); + + Assert.IsTrue(exception.Response.Headers.TryGetValue("Content-Type", out var value)); + Assert.AreEqual("text/json", value); + Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.AreEqual("123", requestId); + Assert.IsInstanceOf(exception.Response.ContentStream); + Assert.AreEqual(0, exception.Response.ContentStream.Position); + Assert.AreEqual("{\"errorCode\": 1}", response.Content.ToString()); } [Test] @@ -160,6 +186,10 @@ public async Task DoesntFormatsResponseContentForNonTextContentTypes() RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); Assert.AreEqual(formattedResponse, exception.Message); + + Assert.IsInstanceOf(exception.Response.ContentStream); + Assert.AreEqual(0, exception.Response.ContentStream.Position); + Assert.AreEqual("{\"errorCode\": 1}", response.Content.ToString()); } [Test] @@ -320,6 +350,10 @@ public void ParsesJsonErrors_ResponseCtor_Stream([Values(true, false)] bool canS RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual("StatusCode", exception.ErrorCode); + + Assert.IsInstanceOf(exception.Response.ContentStream); + Assert.AreEqual(0, exception.Response.ContentStream.Position); + Assert.AreEqual("{ \"error\": { \"code\":\"StatusCode\", \"message\":\"Custom message\" }}", response.Content.ToString()); } [Test] @@ -345,6 +379,10 @@ public async Task ParsesJsonErrors_ResponseCtor_StreamAsync([Values(true, false) RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual("StatusCode", exception.ErrorCode); + + Assert.IsInstanceOf(exception.Response.ContentStream); + Assert.AreEqual(0, exception.Response.ContentStream.Position); + Assert.AreEqual("{ \"error\": { \"code\":\"StatusCode\", \"message\":\"Custom message\" }}", response.Content.ToString()); } [Test] @@ -418,7 +456,7 @@ private Stream GetStream(bool isSeekable, string content) false => new UnSeekableStream(_stream) }; } - private class UnSeekableStream : MemoryStream + private class UnSeekableStream : Stream { private readonly MemoryStream _stream; public UnSeekableStream(MemoryStream stream) @@ -454,10 +492,6 @@ public override void Close() { _stream.Close(); } - public override bool TryGetBuffer(out ArraySegment buffer) - { - return _stream.TryGetBuffer(out buffer); - } public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { @@ -481,6 +515,11 @@ public override void EndWrite(IAsyncResult asyncResult) _stream.EndWrite(asyncResult); } + public override void Flush() + { + _stream.Flush(); + } + public override bool Equals(object obj) { return _stream.Equals(obj); @@ -511,6 +550,16 @@ public override int ReadByte() return _stream.ReadByte(); } + public override long Seek(long offset, SeekOrigin origin) + { + return _stream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + _stream.SetLength(value); + } + public override string ToString() { return _stream.ToString(); From 111ab1b8fcac00fa418a3b5001a0ac1f7a625f10 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:13:12 -0700 Subject: [PATCH 02/16] Use ctor --- .../src/TestEnvironment.cs | 4 +- .../src/Shared/ClientDiagnostics.cs | 159 ------------------ .../src/Shared/OperationInternalBase.cs | 4 - .../src/Shared/OperationInternalOfT.cs | 2 +- .../Resources/Custom/ArmRestApiCollection.cs | 2 - .../src/Resources/Custom/GenericResource.cs | 4 +- .../Custom/GenericResourceCollection.cs | 4 +- .../Custom/RestOperations/RestOperations.cs | 4 +- 8 files changed, 9 insertions(+), 174 deletions(-) diff --git a/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs b/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs index fa1b62a3fc931..bea5286ff8151 100644 --- a/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs +++ b/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs @@ -344,7 +344,7 @@ private async Task ExtendResourceGroupExpirationAsync() // unexpected response => throw an exception if (response.Status != 200) { - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response); + throw new RequestFailedException(response); } // parse the response @@ -392,7 +392,7 @@ private async Task ExtendResourceGroupExpirationAsync() response = await pipeline.SendRequestAsync(request, CancellationToken.None); if (response.Status != 200) { - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response); + throw new RequestFailedException(response); } } } diff --git a/sdk/core/Azure.Core/src/Shared/ClientDiagnostics.cs b/sdk/core/Azure.Core/src/Shared/ClientDiagnostics.cs index 9063d7d0e84d3..81a1859b1b973 100644 --- a/sdk/core/Azure.Core/src/Shared/ClientDiagnostics.cs +++ b/sdk/core/Azure.Core/src/Shared/ClientDiagnostics.cs @@ -18,10 +18,6 @@ namespace Azure.Core.Pipeline { internal class ClientDiagnostics : DiagnosticScopeFactory { - private const string DefaultMessage = "Service request failed."; - - private readonly HttpMessageSanitizer _sanitizer; - /// /// Initializes a new instance of the class. /// @@ -55,7 +51,6 @@ public ClientDiagnostics(ClientOptions options, bool? suppressNestedClientActivi public ClientDiagnostics(string optionsNamespace, string? providerNamespace, DiagnosticsOptions diagnosticsOptions, bool? suppressNestedClientActivities = null) : base(optionsNamespace, providerNamespace, diagnosticsOptions.IsDistributedTracingEnabled, suppressNestedClientActivities.GetValueOrDefault(false)) { - _sanitizer = CreateMessageSanitizer(diagnosticsOptions); } internal static HttpMessageSanitizer CreateMessageSanitizer(DiagnosticsOptions diagnostics) @@ -65,154 +60,6 @@ internal static HttpMessageSanitizer CreateMessageSanitizer(DiagnosticsOptions d diagnostics.LoggedHeaderNames.ToArray()); } - internal static ResponseError? ExtractAzureErrorContent(string? content) - { - try - { - // Optimistic check for JSON object we expect - if (content == null || - !content.StartsWith("{", StringComparison.OrdinalIgnoreCase)) return null; - - return JsonSerializer.Deserialize(content)?.Error; - } - catch (Exception) - { - // Ignore any failures - unexpected content will be - // included verbatim in the detailed error message - } - - return null; - } - - public async ValueTask CreateRequestFailedExceptionAsync(Response response, ResponseError? error = null, IDictionary? additionalInfo = null, Exception? innerException = null) - { - if (GetType() == typeof(ClientDiagnostics) && error is null && additionalInfo is null) - { - return new RequestFailedException(response, innerException); - } - - var content = await ReadContentAsync(response, true).ConfigureAwait(false); - return CreateRequestFailedExceptionWithContent(response, error, content, additionalInfo, innerException); - } - - public RequestFailedException CreateRequestFailedException(Response response, ResponseError? error = null, IDictionary? additionalInfo = null, Exception? innerException = null) - { - if (GetType() == typeof(ClientDiagnostics) && error is null && additionalInfo is null) - { - return new RequestFailedException(response, innerException); - } - - string? content = ReadContentAsync(response, false).EnsureCompleted(); - return CreateRequestFailedExceptionWithContent(response, error, content, additionalInfo, innerException); - } - - private RequestFailedException CreateRequestFailedExceptionWithContent( - Response response, - ResponseError? error = null, - string? content = null, - IDictionary? additionalInfo = null, - Exception? innerException = null) - { - error ??= ExtractAzureErrorContent(content); - var formatMessage = CreateRequestFailedMessageWithContent(response, error, content, additionalInfo, _sanitizer); - var exception = new RequestFailedException(response.Status, formatMessage, error?.Code, innerException); - - if (additionalInfo != null) - { - foreach (KeyValuePair keyValuePair in additionalInfo) - { - exception.Data.Add(keyValuePair.Key, keyValuePair.Value); - } - } - - return exception; - } - - public async ValueTask CreateRequestFailedMessageAsync(Response response, ResponseError? error, IDictionary? additionalInfo, bool async) - { - var content = await ReadContentAsync(response, async).ConfigureAwait(false); - return CreateRequestFailedMessageWithContent(response, error, content, additionalInfo, _sanitizer); - } - - internal static string CreateRequestFailedMessageWithContent(Response response, ResponseError? error, string? content, IDictionary? additionalInfo, HttpMessageSanitizer sanitizer) - { - StringBuilder messageBuilder = new StringBuilder(); - - messageBuilder - .AppendLine(error?.Message ?? DefaultMessage) - .Append("Status: ") - .Append(response.Status.ToString(CultureInfo.InvariantCulture)); - - if (!string.IsNullOrEmpty(response.ReasonPhrase)) - { - messageBuilder.Append(" (") - .Append(response.ReasonPhrase) - .AppendLine(")"); - } - else - { - messageBuilder.AppendLine(); - } - - if (!string.IsNullOrWhiteSpace(error?.Code)) - { - messageBuilder.Append("ErrorCode: ") - .Append(error?.Code) - .AppendLine(); - } - - if (additionalInfo != null && additionalInfo.Count > 0) - { - messageBuilder - .AppendLine() - .AppendLine("Additional Information:"); - foreach (KeyValuePair info in additionalInfo) - { - messageBuilder - .Append(info.Key) - .Append(": ") - .AppendLine(info.Value); - } - } - - if (content != null) - { - messageBuilder - .AppendLine() - .AppendLine("Content:") - .AppendLine(content); - } - - messageBuilder - .AppendLine() - .AppendLine("Headers:"); - - foreach (HttpHeader responseHeader in response.Headers) - { - string headerValue = sanitizer.SanitizeHeader(responseHeader.Name, responseHeader.Value); - string header = $"{responseHeader.Name}: {headerValue}"; - messageBuilder.AppendLine(header); - } - - return messageBuilder.ToString(); - } - - internal static async ValueTask ReadContentAsync(Response response, bool async) - { - string? content = null; - - if (response.ContentStream != null && - ContentTypeUtilities.TryGetTextEncoding(response.Headers.ContentType, out var encoding)) - { - using (var streamReader = new StreamReader(response.ContentStream, encoding)) - { - content = async ? await streamReader.ReadToEndAsync().ConfigureAwait(false) : streamReader.ReadToEnd(); - } - } - - return content; - } - internal static string? GetResourceProviderNamespace(Assembly assembly) { foreach (var customAttribute in assembly.GetCustomAttributes(true)) @@ -227,11 +74,5 @@ internal static string CreateRequestFailedMessageWithContent(Response response, return null; } - - private class ErrorResponse - { - [JsonPropertyName("error")] - public ResponseError? Error { get; set; } - } } } diff --git a/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs b/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs index 7781deee28640..dad6480c22ce7 100644 --- a/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs +++ b/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs @@ -230,9 +230,5 @@ protected DiagnosticScope CreateScope(string scopeName) scope.Start(); return scope; } - - protected async ValueTask CreateException(bool async, Response response) => async - ? await _diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _diagnostics.CreateRequestFailedException(response); } } diff --git a/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs b/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs index c4666e788c3da..66c7a71e561ac 100644 --- a/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs +++ b/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs @@ -281,7 +281,7 @@ protected override async ValueTask UpdateStatusAsync(bool async, Cance if (!state.HasSucceeded && state.OperationFailedException == null) { - state = OperationState.Failure(state.RawResponse, await CreateException(async, state.RawResponse).ConfigureAwait(false)); + state = OperationState.Failure(state.RawResponse, new RequestFailedException(state.RawResponse)); } asyncLock.SetValue(state); diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs index b94faa635c0c3..33570d8e8f680 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// - #nullable disable using System; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResource.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResource.cs index 54f9f402fa88b..d3ab3aa863907 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResource.cs @@ -89,7 +89,7 @@ public async virtual Task> GetAsync(CancellationToken var apiVersion = await GetApiVersionAsync(cancellationToken).ConfigureAwait(false); var response = await _resourcesRestClient.GetByIdAsync(Id, apiVersion, cancellationToken).ConfigureAwait(false); if (response.Value == null) - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response.GetRawResponse()).ConfigureAwait(false); + throw new RequestFailedException(response.GetRawResponse()); return Response.FromValue(new GenericResource(Client, response.Value), response.GetRawResponse()); } catch (Exception e) @@ -113,7 +113,7 @@ public virtual Response Get(CancellationToken cancellationToken var apiVersion = GetApiVersion(cancellationToken); var response = _resourcesRestClient.GetById(Id, apiVersion, cancellationToken); if (response.Value == null) - throw _clientDiagnostics.CreateRequestFailedException(response.GetRawResponse()); + throw new RequestFailedException(response.GetRawResponse()); return Response.FromValue(new GenericResource(Client, response.Value), response.GetRawResponse()); } catch (Exception e) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResourceCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResourceCollection.cs index dcae2e1806664..21a02e378e007 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResourceCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/GenericResourceCollection.cs @@ -138,7 +138,7 @@ public virtual Response Get(ResourceIdentifier resourceId, Canc var apiVersion = GetApiVersion(new ResourceIdentifier(resourceId), cancellationToken); var response = _resourcesRestClient.GetById(resourceId, apiVersion, cancellationToken); if (response.Value == null) - throw _clientDiagnostics.CreateRequestFailedException(response.GetRawResponse()); + throw new RequestFailedException(response.GetRawResponse()); return Response.FromValue(new GenericResource(Client, response.Value), response.GetRawResponse()); } catch (Exception e) @@ -169,7 +169,7 @@ public async virtual Task> GetAsync(ResourceIdentifier var apiVersion = await GetApiVersionAsync(new ResourceIdentifier(resourceId), cancellationToken).ConfigureAwait(false); var response = await _resourcesRestClient.GetByIdAsync(resourceId, apiVersion, cancellationToken).ConfigureAwait(false); if (response.Value == null) - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response.GetRawResponse()).ConfigureAwait(false); + throw new RequestFailedException(response.GetRawResponse()); return Response.FromValue(new GenericResource(Client, response.Value), response.GetRawResponse()); } catch (Exception e) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/RestOperations/RestOperations.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/RestOperations/RestOperations.cs index 7821f8928ccd2..9652d2393f588 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/RestOperations/RestOperations.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/RestOperations/RestOperations.cs @@ -80,7 +80,7 @@ public async Task> ListAsync(CancellationToken ca return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -100,7 +100,7 @@ public Response List(CancellationToken cancellationToken = return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } From cfe6cda6a302ec7674f6ce20f6187a73379fc4c6 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:29:43 -0700 Subject: [PATCH 03/16] Fix tests --- .../tests/FailedResponseExceptionTests.cs | 59 +++++++++++-------- .../Resources/Custom/ArmRestApiCollection.cs | 1 - 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs b/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs index d0a7092be66af..698b386e43835 100644 --- a/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs +++ b/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs @@ -23,7 +23,7 @@ public class FailedResponseExceptionTests private static HttpMessageSanitizer Sanitizer = new TestClientOption().Sanitizer; [Test] - public async Task FormatsResponse() + public void FormatsResponse() { var formattedResponse = "Service request failed." + s_nl + @@ -38,7 +38,7 @@ public async Task FormatsResponse() response.AddHeader(new HttpHeader("x-ms-requestId", "123")); response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); @@ -100,7 +100,7 @@ public void FormatsResponseWithoutSanitizer_ResponseCtor() } [Test] - public async Task HeadersAreSanitized() + public void HeadersAreSanitized() { var formattedResponse = "Service request failed." + s_nl + @@ -114,7 +114,7 @@ public async Task HeadersAreSanitized() response.AddHeader(new HttpHeader("Custom-Header-2", "Value")); response.AddHeader(new HttpHeader("x-ms-requestId-2", "123")); - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); } @@ -138,7 +138,7 @@ public void HeadersAreSanitized_ResponseCtor() } [Test] - public async Task FormatsResponseContentForTextContentTypes() + public void FormatsResponseContentForTextContentTypes() { var formattedResponse = "Service request failed." + s_nl + @@ -157,7 +157,7 @@ public async Task FormatsResponseContentForTextContentTypes() response.SetContent("{\"errorCode\": 1}"); response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.IsTrue(exception.Response.Headers.TryGetValue("Content-Type", out var value)); @@ -170,7 +170,7 @@ public async Task FormatsResponseContentForTextContentTypes() } [Test] - public async Task DoesntFormatsResponseContentForNonTextContentTypes() + public void DoesntFormatsResponseContentForNonTextContentTypes() { var formattedResponse = "Service request failed." + s_nl + @@ -184,7 +184,7 @@ public async Task DoesntFormatsResponseContentForNonTextContentTypes() response.SetContent("{\"errorCode\": 1}"); response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.IsInstanceOf(exception.Response.ContentStream); @@ -193,7 +193,7 @@ public async Task DoesntFormatsResponseContentForNonTextContentTypes() } [Test] - public async Task IncludesErrorCodeInMessageIfAvailable() + public void IncludesErrorCodeInMessageIfAvailable() { var formattedResponse = "Service request failed." + s_nl + @@ -207,13 +207,15 @@ public async Task IncludesErrorCodeInMessageIfAvailable() var response = new MockResponse(210, "Reason"); response.AddHeader(new HttpHeader("Custom-Header", "Value")); response.AddHeader(new HttpHeader("x-ms-requestId", "123")); + response.SetContent("{ \"error\": { \"code\":\"CUSTOM CODE\" }}"); + response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response, new ResponseError("CUSTOM CODE", null)); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); } [Test] - public async Task IncludesAdditionalInformationIfAvailable() + public void IncludesAdditionalInformationIfAvailable() { var formattedResponse = "Service request failed." + s_nl + @@ -230,12 +232,11 @@ public async Task IncludesAdditionalInformationIfAvailable() var response = new MockResponse(210, "Reason"); response.AddHeader(new HttpHeader("Custom-Header", "Value")); response.AddHeader(new HttpHeader("x-ms-requestId", "123")); + response.SetContent("{ \"a\": \"a-value\", \"b\": \"b-value\" }"); + response.Sanitizer = Sanitizer; + response.RequestFailedDetailsParser = new CustomParser(); - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response, additionalInfo: new Dictionary() - { - {"a", "a-value"}, - {"b", "b-value"}, - }); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual("a-value", exception.Data["a"]); @@ -243,7 +244,7 @@ public async Task IncludesAdditionalInformationIfAvailable() } [Test] - public async Task IncludesInnerException() + public void IncludesInnerException() { var formattedResponse = "Service request failed." + s_nl + @@ -259,7 +260,7 @@ public async Task IncludesInnerException() response.Sanitizer = Sanitizer; var innerException = new Exception(); - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response, innerException: innerException); + RequestFailedException exception = new RequestFailedException(response, innerException: innerException); Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual(innerException, exception.InnerException); } @@ -281,7 +282,7 @@ public void RequestFailedExceptionIsSerializeable() } [Test] - public async Task ParsesJsonErrors() + public void ParsesJsonErrors() { var formattedResponse = "Custom message" + s_nl + @@ -299,7 +300,7 @@ public async Task ParsesJsonErrors() response.AddHeader(new HttpHeader("Content-Type", "text/json")); response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual("StatusCode", exception.ErrorCode); } @@ -386,7 +387,7 @@ public async Task ParsesJsonErrors_ResponseCtor_StreamAsync([Values(true, false) } [Test] - public async Task IgnoresInvalidJsonErrors() + public void IgnoresInvalidJsonErrors() { var formattedResponse = "Service request failed." + s_nl + @@ -403,12 +404,12 @@ public async Task IgnoresInvalidJsonErrors() response.AddHeader(new HttpHeader("Content-Type", "text/json")); response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); } [Test] - public async Task IgnoresNonStandardJson() + public void IgnoresNonStandardJson() { var formattedResponse = "Service request failed." + s_nl + @@ -425,7 +426,7 @@ public async Task IgnoresNonStandardJson() response.AddHeader(new HttpHeader("Content-Type", "text/json")); response.Sanitizer = Sanitizer; - RequestFailedException exception = await ClientDiagnostics.CreateRequestFailedExceptionAsync(response); + RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); } @@ -580,5 +581,15 @@ public override void WriteByte(byte value) _stream.WriteByte(value); } } + + private class CustomParser : RequestFailedDetailsParser + { + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + RequestFailedException.TryExtractErrorContent(response, out error, out data); + data = response.Content.ToObjectFromJson>(); + return true; + } + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs index 33570d8e8f680..25e587549eccf 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ArmRestApiCollection.cs @@ -42,7 +42,6 @@ internal ArmRestApiCollection(ArmResource operation, string nameSpace) _providerCollection = new ResourceProviderCollection(Client.GetSubscriptionResource(Id)); } - private RestOperations GetRestClient(CancellationToken cancellationToken = default) { return _restClient ??= new RestOperations( From bc4bb5dfe7787c9df82307c52d079dba526431ec Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:33:40 -0700 Subject: [PATCH 04/16] Use a method --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net5.0.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs | 2 +- sdk/core/Azure.Core/src/RequestFailedException.cs | 9 +++++++-- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 4c304f46e9c4c..d4d2ab9fe00c0 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -227,9 +227,9 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } - public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + public Azure.Response? GetRawResponse() { throw null; } } public abstract partial class Response : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs index 702382dcedeec..a5675287237a2 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs @@ -227,9 +227,9 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } - public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + public Azure.Response? GetRawResponse() { throw null; } } public abstract partial class Response : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index 702382dcedeec..a5675287237a2 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -227,9 +227,9 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } - public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + public Azure.Response? GetRawResponse() { throw null; } } public abstract partial class Response : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs index 4c304f46e9c4c..d4d2ab9fe00c0 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs @@ -227,9 +227,9 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } - public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + public Azure.Response? GetRawResponse() { throw null; } } public abstract partial class Response : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 4c304f46e9c4c..d4d2ab9fe00c0 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -227,9 +227,9 @@ protected RequestFailedException(System.Runtime.Serialization.SerializationInfo public RequestFailedException(string message) { } public RequestFailedException(string message, System.Exception? innerException) { } public string? ErrorCode { get { throw null; } } - public Azure.Response? Response { get { throw null; } } public int Status { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + public Azure.Response? GetRawResponse() { throw null; } } public abstract partial class Response : System.IDisposable { diff --git a/sdk/core/Azure.Core/src/RequestFailedException.cs b/sdk/core/Azure.Core/src/RequestFailedException.cs index 0a81bf8803632..bc293de3c27f2 100644 --- a/sdk/core/Azure.Core/src/RequestFailedException.cs +++ b/sdk/core/Azure.Core/src/RequestFailedException.cs @@ -34,7 +34,7 @@ public class RequestFailedException : Exception, ISerializable /// /// Gets the response, if any, that led to the exception. /// - public Response? Response { get; } + private readonly Response? _response; /// Initializes a new instance of the class with a specified error message. /// The message that describes the error. @@ -110,7 +110,7 @@ public RequestFailedException(Response response) public RequestFailedException(Response response, Exception? innerException) : this(response.Status, GetRequestFailedExceptionContent(response), innerException) { - Response = response; + _response = response; } /// @@ -132,6 +132,11 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont base.GetObjectData(info, context); } + /// + /// Gets the response, if any, that led to the exception. + /// + public Response? GetRawResponse() => _response; + internal static (string FormattedError, string? ErrorCode, IDictionary? Data) GetRequestFailedExceptionContent(Response response) { BufferResponseIfNeeded(response); From 2b67600610009ef93bca67735efe4c35fc9898d4 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:39:28 -0700 Subject: [PATCH 05/16] change log --- sdk/core/Azure.Core/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/core/Azure.Core/CHANGELOG.md b/sdk/core/Azure.Core/CHANGELOG.md index fc7b34aa83b61..f02f87fc7e389 100644 --- a/sdk/core/Azure.Core/CHANGELOG.md +++ b/sdk/core/Azure.Core/CHANGELOG.md @@ -4,6 +4,9 @@ ### Features Added +- Added the `GetRawResponse` method to `RequestFailedException`. +- Added overloads of `Operation.WaitForCompletion` and `Operation.WaitForCompletionResponse` that take a `DelayStrategy`. + ### Breaking Changes ### Bugs Fixed From 0847dc211b3aa5d9b4f73d9c249759cb4f46e326 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:48:48 -0700 Subject: [PATCH 06/16] Fix tests --- .../tests/FailedResponseExceptionTests.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs b/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs index 698b386e43835..03db4195159aa 100644 --- a/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs +++ b/sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs @@ -41,11 +41,12 @@ public void FormatsResponse() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); - Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); + Response rawResponse = exception.GetRawResponse(); + Assert.IsTrue(rawResponse.Headers.TryGetValue("Custom-Header", out var value)); Assert.AreEqual("Value", value); - Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.IsTrue(rawResponse.Headers.TryGetValue("x-ms-requestId", out var requestId)); Assert.AreEqual("123", requestId); - Assert.IsNull(exception.Response.ContentStream); + Assert.IsNull(rawResponse.ContentStream); } [Test] @@ -67,11 +68,12 @@ public void FormatsResponse_ResponseCtor() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); - Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); + Response rawResponse = exception.GetRawResponse(); + Assert.IsTrue(rawResponse.Headers.TryGetValue("Custom-Header", out var value)); Assert.AreEqual("Value", value); - Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.IsTrue(rawResponse.Headers.TryGetValue("x-ms-requestId", out var requestId)); Assert.AreEqual("123", requestId); - Assert.IsNull(exception.Response.ContentStream); + Assert.IsNull(rawResponse.ContentStream); } [Test] @@ -92,11 +94,12 @@ public void FormatsResponseWithoutSanitizer_ResponseCtor() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); - Assert.IsTrue(exception.Response.Headers.TryGetValue("Custom-Header", out var value)); + Response rawResponse = exception.GetRawResponse(); + Assert.IsTrue(rawResponse.Headers.TryGetValue("Custom-Header", out var value)); Assert.AreEqual("Value", value); - Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.IsTrue(rawResponse.Headers.TryGetValue("x-ms-requestId", out var requestId)); Assert.AreEqual("123", requestId); - Assert.IsNull(exception.Response.ContentStream); + Assert.IsNull(rawResponse.ContentStream); } [Test] @@ -160,13 +163,14 @@ public void FormatsResponseContentForTextContentTypes() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); - Assert.IsTrue(exception.Response.Headers.TryGetValue("Content-Type", out var value)); + Response rawResponse = exception.GetRawResponse(); + Assert.IsTrue(rawResponse.Headers.TryGetValue("Content-Type", out var value)); Assert.AreEqual("text/json", value); - Assert.IsTrue(exception.Response.Headers.TryGetValue("x-ms-requestId", out var requestId)); + Assert.IsTrue(rawResponse.Headers.TryGetValue("x-ms-requestId", out var requestId)); Assert.AreEqual("123", requestId); - Assert.IsInstanceOf(exception.Response.ContentStream); - Assert.AreEqual(0, exception.Response.ContentStream.Position); - Assert.AreEqual("{\"errorCode\": 1}", response.Content.ToString()); + Assert.IsInstanceOf(rawResponse.ContentStream); + Assert.AreEqual(0, rawResponse.ContentStream.Position); + Assert.AreEqual("{\"errorCode\": 1}", rawResponse.Content.ToString()); } [Test] @@ -186,10 +190,11 @@ public void DoesntFormatsResponseContentForNonTextContentTypes() RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); + Response rawResponse = exception.GetRawResponse(); - Assert.IsInstanceOf(exception.Response.ContentStream); - Assert.AreEqual(0, exception.Response.ContentStream.Position); - Assert.AreEqual("{\"errorCode\": 1}", response.Content.ToString()); + Assert.IsInstanceOf(rawResponse.ContentStream); + Assert.AreEqual(0, rawResponse.ContentStream.Position); + Assert.AreEqual("{\"errorCode\": 1}", rawResponse.Content.ToString()); } [Test] @@ -351,10 +356,11 @@ public void ParsesJsonErrors_ResponseCtor_Stream([Values(true, false)] bool canS RequestFailedException exception = new RequestFailedException(response); Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual("StatusCode", exception.ErrorCode); + Response rawResponse = exception.GetRawResponse(); - Assert.IsInstanceOf(exception.Response.ContentStream); - Assert.AreEqual(0, exception.Response.ContentStream.Position); - Assert.AreEqual("{ \"error\": { \"code\":\"StatusCode\", \"message\":\"Custom message\" }}", response.Content.ToString()); + Assert.IsInstanceOf(rawResponse.ContentStream); + Assert.AreEqual(0, rawResponse.ContentStream.Position); + Assert.AreEqual("{ \"error\": { \"code\":\"StatusCode\", \"message\":\"Custom message\" }}", rawResponse.Content.ToString()); } [Test] @@ -381,9 +387,10 @@ public async Task ParsesJsonErrors_ResponseCtor_StreamAsync([Values(true, false) Assert.AreEqual(formattedResponse, exception.Message); Assert.AreEqual("StatusCode", exception.ErrorCode); - Assert.IsInstanceOf(exception.Response.ContentStream); - Assert.AreEqual(0, exception.Response.ContentStream.Position); - Assert.AreEqual("{ \"error\": { \"code\":\"StatusCode\", \"message\":\"Custom message\" }}", response.Content.ToString()); + Response rawResponse = exception.GetRawResponse(); + Assert.IsInstanceOf(rawResponse.ContentStream); + Assert.AreEqual(0, rawResponse.ContentStream.Position); + Assert.AreEqual("{ \"error\": { \"code\":\"StatusCode\", \"message\":\"Custom message\" }}", rawResponse.Content.ToString()); } [Test] From 64e7d5ba9026e741ad2d55ed6d0aa33892efb966 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:11:52 -0700 Subject: [PATCH 07/16] Update search --- .../Azure.Search.Documents/src/SearchClient.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/sdk/search/Azure.Search.Documents/src/SearchClient.cs b/sdk/search/Azure.Search.Documents/src/SearchClient.cs index e63b203667af1..3f3792d21c6f7 100644 --- a/sdk/search/Azure.Search.Documents/src/SearchClient.cs +++ b/sdk/search/Azure.Search.Documents/src/SearchClient.cs @@ -705,9 +705,7 @@ private async Task> GetDocumentInternal( return Response.FromValue(value, message.Response); } default: - throw async ? - await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception e) @@ -895,9 +893,7 @@ private async Task>> SearchInternal( return Response.FromValue(results, message.Response); } default: - throw async ? - await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception e) @@ -1060,9 +1056,7 @@ private async Task>> SuggestInternal( return Response.FromValue(suggestions, message.Response); } default: - throw async ? - await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception e) @@ -1391,9 +1385,7 @@ await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellat return Response.FromValue(value, message.Response); } default: - throw async ? - await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception e) From 9d48d0e4c2bd5e6adaea42f18133322f24595ab5 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:43:32 -0700 Subject: [PATCH 08/16] KeyVault --- .../src/CertificateClient.cs | 4 ++-- .../src/DeleteCertificateOperation.cs | 6 +----- .../src/RecoverDeletedCertificateOperation.cs | 6 +----- .../src/Cryptography/KeyResolver.cs | 2 +- .../Azure.Security.KeyVault.Keys/src/DeleteKeyOperation.cs | 6 +----- .../src/RecoverDeletedKeyOperation.cs | 6 +----- .../src/DeleteSecretOperation.cs | 6 +----- .../src/RecoverDeletedSecretOperation.cs | 6 +----- .../Azure.Security.KeyVault.Shared/src/KeyVaultPipeline.cs | 4 ++-- 9 files changed, 11 insertions(+), 35 deletions(-) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClient.cs index ca5f1f0c3885e..8d2491186f1d4 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/CertificateClient.cs @@ -1665,7 +1665,7 @@ internal virtual Response GetPendingCertificate( return Response.FromValue(null, response); default: - throw _pipeline.Diagnostics.CreateRequestFailedException(response); + throw new RequestFailedException(response); } } catch (Exception e) @@ -1696,7 +1696,7 @@ internal virtual async Task> GetPending return Response.FromValue(null, response); default: - throw await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false); + throw new RequestFailedException(response); } } catch (Exception e) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/DeleteCertificateOperation.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/DeleteCertificateOperation.cs index 175974e732f6d..e08a41bdf9775 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/DeleteCertificateOperation.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/DeleteCertificateOperation.cs @@ -111,11 +111,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella return OperationState.Pending(response); default: - RequestFailedException ex = async - ? await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _pipeline.Diagnostics.CreateRequestFailedException(response); - - return OperationState.Failure(response, ex); + return OperationState.Failure(response, new RequestFailedException(response)); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/RecoverDeletedCertificateOperation.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/RecoverDeletedCertificateOperation.cs index 11fcd7df578a2..7f4468db56af4 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/RecoverDeletedCertificateOperation.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/RecoverDeletedCertificateOperation.cs @@ -101,11 +101,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella return OperationState.Pending(response); default: - RequestFailedException ex = async - ? await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _pipeline.Diagnostics.CreateRequestFailedException(response); - - return OperationState.Failure(response, ex); + return OperationState.Failure(response, new RequestFailedException(response)); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/KeyResolver.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/KeyResolver.cs index 60583c9c635b5..05b6ebc17b3f1 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/KeyResolver.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/KeyResolver.cs @@ -173,7 +173,7 @@ private Response ParseResponse(Response response, T result) // To use a key contained within a secret, the "get" permission is required to retrieve the key material. return Response.FromValue(default, response); default: - throw _clientDiagnostics.CreateRequestFailedException(response); + throw new RequestFailedException(response); } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/DeleteKeyOperation.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/DeleteKeyOperation.cs index 96b9d3c5dfe32..c35af7cc1c9a6 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/DeleteKeyOperation.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/DeleteKeyOperation.cs @@ -111,11 +111,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella return OperationState.Pending(response); default: - RequestFailedException ex = async - ? await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _pipeline.Diagnostics.CreateRequestFailedException(response); - - return OperationState.Failure(response, ex); + return OperationState.Failure(response, new RequestFailedException(response)); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/RecoverDeletedKeyOperation.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/RecoverDeletedKeyOperation.cs index 71fd05e63e144..3614f8a4a9b3e 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/RecoverDeletedKeyOperation.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/RecoverDeletedKeyOperation.cs @@ -101,11 +101,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella return OperationState.Pending(response); default: - RequestFailedException ex = async - ? await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _pipeline.Diagnostics.CreateRequestFailedException(response); - - return OperationState.Failure(response, ex); + return OperationState.Failure(response, new RequestFailedException(response)); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/DeleteSecretOperation.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/DeleteSecretOperation.cs index fb4be907d6ed4..79258ddc9d436 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/DeleteSecretOperation.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/DeleteSecretOperation.cs @@ -107,11 +107,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella return OperationState.Pending(response); default: - RequestFailedException ex = async - ? await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _pipeline.Diagnostics.CreateRequestFailedException(response); - - return OperationState.Failure(response, ex); + return OperationState.Failure(response, new RequestFailedException(response)); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/RecoverDeletedSecretOperation.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/RecoverDeletedSecretOperation.cs index bbae1598c216a..bdfc212ba0001 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/RecoverDeletedSecretOperation.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/RecoverDeletedSecretOperation.cs @@ -97,11 +97,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella return OperationState.Pending(response); default: - RequestFailedException ex = async - ? await _pipeline.Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : _pipeline.Diagnostics.CreateRequestFailedException(response); - - return OperationState.Failure(response, ex); + return OperationState.Failure(response, new RequestFailedException(response)); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Shared/src/KeyVaultPipeline.cs b/sdk/keyvault/Azure.Security.KeyVault.Shared/src/KeyVaultPipeline.cs index 24eb3e889b120..cbec6199ee5f2 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Shared/src/KeyVaultPipeline.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Shared/src/KeyVaultPipeline.cs @@ -263,7 +263,7 @@ private async Task SendRequestAsync(Request request, CancellationToken case 204: return response; default: - throw await Diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false); + throw new RequestFailedException(response); } } private Response SendRequest(Request request, CancellationToken cancellationToken) @@ -278,7 +278,7 @@ private Response SendRequest(Request request, CancellationToken cancellationToke case 204: return response; default: - throw Diagnostics.CreateRequestFailedException(response); + throw new RequestFailedException(response); } } } From 833c8a59b183c7e2c249e767ef5c1b5de5df629b Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Mon, 1 May 2023 15:41:21 -0700 Subject: [PATCH 09/16] Update more libraries --- .../src/Azure.Data.AppConfiguration.csproj | 3 + .../src/ConfigurationClient.cs | 32 ++++---- .../src/CallRecording.cs | 4 +- .../src/Downloader/ContentDownloader.cs | 4 +- .../src/CallRecording.cs | 4 +- .../src/Downloader/ContentDownloader.cs | 4 +- .../src/ChatThreadClient.cs | 4 +- .../Generated/SipRoutingRestClient.cs | 4 +- .../src/SipRouting/SipRoutingRestClient.cs | 4 +- .../Azure.Security.ConfidentialLedger.csproj | 3 + .../src/PostLedgerEntryOperation.cs | 4 +- .../Pipeline/RequestFailedDetailsParser.cs | 2 +- .../Azure.Core/src/RequestFailedException.cs | 38 ++++++++-- .../tests/FailedResponseExceptionTests.cs | 1 + .../Customized/DigitalTwinModelsRestClient.cs | 8 +- .../src/Customized/DigitalTwinsRestClient.cs | 36 ++++----- .../src/Customized/QueryRestClient.cs | 4 +- .../src/EventGridPublisherClient.cs | 16 +--- .../Azure.AI.FormRecognizer.sln | 6 ++ .../src/AnalyzeDocumentOperation.cs | 4 +- .../src/Azure.AI.FormRecognizer.csproj | 3 + .../src/BuildDocumentClassifierOperation.cs | 4 +- .../src/BuildDocumentModelOperation.cs | 4 +- .../src/ClassifyDocumentOperation.cs | 4 +- .../src/ComposeDocumentModelOperation.cs | 4 +- .../src/CopyDocumentModelToOperation.cs | 4 +- .../RecognizeBusinessCardsOperation.cs | 4 +- .../RecognizeContentOperation.cs | 4 +- .../RecognizeCustomFormsOperation.cs | 4 +- .../RecognizeIdentityDocumentsOperation.cs | 4 +- .../RecognizeInvoicesOperation.cs | 4 +- .../RecognizeReceiptsOperation.cs | 4 +- .../FormTrainingClient/CopyModelOperation.cs | 4 +- .../CreateCustomFormModelOperation.cs | 10 +-- .../src/Internal/ClientCommon.cs | 12 +-- sdk/identity/Azure.Identity.sln | 6 ++ .../Azure.Identity/src/Azure.Identity.csproj | 5 +- .../src/ImdsManagedIdentitySource.cs | 2 +- .../src/Customized/JobsRestClient.cs | 4 +- .../src/Fetchers/HttpModelFetcher.cs | 4 +- .../src/LogsQueryClient.cs | 18 +---- .../tests/LogSenderClient.cs | 2 +- .../tests/MetricsSenderClient.cs | 2 +- .../src/Generated/EvaluationsRestClient.cs | 16 ++-- .../src/Generated/EventsRestClient.cs | 8 +- .../src/Generated/LogRestClient.cs | 8 +- .../src/Generated/ModelRestClient.cs | 16 ++-- .../Generated/MultiSlotEventsRestClient.cs | 8 +- .../src/Generated/MultiSlotRestClient.cs | 4 +- .../src/Generated/PolicyRestClient.cs | 12 +-- .../src/Generated/RankRestClient.cs | 4 +- .../ServiceConfigurationRestClient.cs | 12 +-- .../Administration/HttpRequestAndResponse.cs | 6 +- .../NamespacePropertiesExtensions.cs | 4 +- .../QueuePropertiesExtensions.cs | 6 +- .../QueueRuntimePropertiesExtensions.cs | 6 +- .../Rules/RuleDescriptionExtensions.cs | 4 +- .../SubscriptionPropertiesExtensions.cs | 6 +- ...SubscriptionRuntimePropertiesExtensions.cs | 12 +-- .../TopicPropertiesExtensions.cs | 6 +- .../TopicRuntimePropertiesExtensions.cs | 6 +- .../src/Azure.Storage.Blobs.Batch.csproj | 3 + .../src/BatchErrors.cs | 2 +- .../src/BlobBatch.cs | 8 +- .../src/BlobBatchClient.cs | 4 +- .../src/DelayedResponse.cs | 8 +- .../tests/DelayedResponseTests.cs | 4 +- .../src/ErrorExtensions.cs | 68 ----------------- .../Azure.Data.Tables/src/TableClient.cs | 2 +- .../Azure.Data.Tables/src/TableRestClient.cs | 2 +- .../Generated/ApplicationsRestOperations.cs | 64 ++++++++-------- .../DeletedApplicationsRestOperations.cs | 20 ++--- .../src/Generated/DomainsRestOperations.cs | 8 +- .../src/Generated/GroupsRestOperations.cs | 68 ++++++++--------- .../OAuth2PermissionGrantRestOperations.cs | 20 ++--- .../src/Generated/ObjectsRestOperations.cs | 12 +-- .../ServicePrincipalsRestOperations.cs | 76 +++++++++---------- .../Generated/SignedInUserRestOperations.cs | 16 ++-- .../src/Generated/UsersRestOperations.cs | 32 ++++---- .../src/DocumentTranslationOperation.cs | 9 +-- 80 files changed, 396 insertions(+), 475 deletions(-) delete mode 100644 sdk/storage/Azure.Storage.Files.DataLake/src/ErrorExtensions.cs diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Azure.Data.AppConfiguration.csproj b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Azure.Data.AppConfiguration.csproj index 3c8de240007a6..3dd52bb945233 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Azure.Data.AppConfiguration.csproj +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Azure.Data.AppConfiguration.csproj @@ -14,6 +14,9 @@ + + + diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs index 5f7527cc6f942..e8380a25d6142 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs @@ -175,9 +175,9 @@ public virtual async Task> AddConfigurationSettin case 201: return await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false); case 412: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(response, new ResponseError(null, "Setting was already present.")).ConfigureAwait(false); + throw new RequestFailedException(response, null, new ResponseError(null, "Setting was already present.")); default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false); + throw new RequestFailedException(response); } } catch (Exception e) @@ -214,9 +214,9 @@ public virtual Response AddConfigurationSetting(Configurat case 201: return CreateResponse(response); case 412: - throw ClientDiagnostics.CreateRequestFailedException(response, new ResponseError(null, "Setting was already present.")); + throw new RequestFailedException(response, null, new ResponseError(null, "Setting was already present.")); default: - throw ClientDiagnostics.CreateRequestFailedException(response); + throw new RequestFailedException(response); } } catch (Exception e) @@ -283,10 +283,10 @@ public virtual async Task> SetConfigurationSettin return response.Status switch { 200 => await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false), - 409 => throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(response, new ResponseError(null, "The setting is read only")).ConfigureAwait(false), + 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only")), // Throws on 412 if resource was modified. - _ => throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false), + _ => throw new RequestFailedException(response), }; } catch (Exception e) @@ -326,10 +326,10 @@ public virtual Response SetConfigurationSetting(Configurat return response.Status switch { 200 => CreateResponse(response), - 409 => throw ClientDiagnostics.CreateRequestFailedException(response, new ResponseError(null, "The setting is read only")), + 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only")), // Throws on 412 if resource was modified. - _ => throw ClientDiagnostics.CreateRequestFailedException(response), + _ => throw new RequestFailedException(response), }; } catch (Exception e) @@ -415,10 +415,10 @@ private async Task DeleteConfigurationSettingAsync(string key, string { 200 => response, 204 => response, - 409 => throw ClientDiagnostics.CreateRequestFailedException(response, new ResponseError(null, "The setting is read only")), + 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only")), // Throws on 412 if resource was modified. - _ => throw ClientDiagnostics.CreateRequestFailedException(response) + _ => throw new RequestFailedException(response) }; } catch (Exception e) @@ -444,10 +444,10 @@ private Response DeleteConfigurationSetting(string key, string label, MatchCondi { 200 => response, 204 => response, - 409 => throw ClientDiagnostics.CreateRequestFailedException(response, new ResponseError(null, "The setting is read only.")), + 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only.")), // Throws on 412 if resource was modified. - _ => throw ClientDiagnostics.CreateRequestFailedException(response) + _ => throw new RequestFailedException(response) }; } catch (Exception e) @@ -569,7 +569,7 @@ internal virtual async Task> GetConfigurationSett { 200 => await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false), 304 => CreateResourceModifiedResponse(response), - _ => throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false), + _ => throw new RequestFailedException(response), }; } catch (Exception e) @@ -605,7 +605,7 @@ internal virtual Response GetConfigurationSetting(string k { 200 => CreateResponse(response), 304 => CreateResourceModifiedResponse(response), - _ => throw ClientDiagnostics.CreateRequestFailedException(response), + _ => throw new RequestFailedException(response), }; } catch (Exception e) @@ -1370,9 +1370,7 @@ private async ValueTask> SetReadOnlyAsync(string 200 => async ? await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false) : CreateResponse(response), - _ => throw (async - ? await ClientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false) - : ClientDiagnostics.CreateRequestFailedException(response)) + _ => throw new RequestFailedException(response) }; } catch (Exception e) diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/CallRecording.cs b/sdk/communication/Azure.Communication.CallAutomation/src/CallRecording.cs index e7d1697be5226..14bed08c96c4f 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/CallRecording.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/CallRecording.cs @@ -551,7 +551,7 @@ public virtual Response DeleteRecording(Uri recordingLocation, CancellationToken case 200: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception ex) @@ -594,7 +594,7 @@ public virtual async Task DeleteRecordingAsync(Uri recordingLocation, case 200: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception ex) diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Downloader/ContentDownloader.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Downloader/ContentDownloader.cs index 3acfb9bdd8361..d8d5012e39c08 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Downloader/ContentDownloader.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Downloader/ContentDownloader.cs @@ -84,7 +84,7 @@ private async Task> StartDownloadAsync(Uri sourceEndpoint, Http return Response.FromValue(value, message.Response); } default: - throw await _client._clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -113,7 +113,7 @@ private Response StartDownload(Uri sourceEndpoint, HttpRange range = def return Response.FromValue(value, message.Response); } default: - throw _client._clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } diff --git a/sdk/communication/Azure.Communication.CallingServer/src/CallRecording.cs b/sdk/communication/Azure.Communication.CallingServer/src/CallRecording.cs index 9aaef93b9d373..60a7c28b426ad 100644 --- a/sdk/communication/Azure.Communication.CallingServer/src/CallRecording.cs +++ b/sdk/communication/Azure.Communication.CallingServer/src/CallRecording.cs @@ -543,7 +543,7 @@ public virtual Response DeleteRecording(Uri recordingLocation, CancellationToken case 200: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception ex) @@ -586,7 +586,7 @@ public virtual async Task DeleteRecordingAsync(Uri recordingLocation, case 200: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception ex) diff --git a/sdk/communication/Azure.Communication.CallingServer/src/Downloader/ContentDownloader.cs b/sdk/communication/Azure.Communication.CallingServer/src/Downloader/ContentDownloader.cs index 5ca599375d6c1..864233c9d5400 100644 --- a/sdk/communication/Azure.Communication.CallingServer/src/Downloader/ContentDownloader.cs +++ b/sdk/communication/Azure.Communication.CallingServer/src/Downloader/ContentDownloader.cs @@ -84,7 +84,7 @@ private async Task> StartDownloadAsync(Uri sourceEndpoint, Http return Response.FromValue(value, message.Response); } default: - throw await _client._clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -113,7 +113,7 @@ private Response StartDownload(Uri sourceEndpoint, HttpRange range = def return Response.FromValue(value, message.Response); } default: - throw _client._clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } diff --git a/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs b/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs index a4cfc05bcd3ee..970cb47630f2e 100644 --- a/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs +++ b/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs @@ -428,7 +428,7 @@ public virtual async Task AddParticipantAsync(ChatParticipant particip Response addChatParticipantsResult = await _chatThreadRestClient.AddChatParticipantsAsync(Id, new[] { participant.ToChatParticipantInternal() }, cancellationToken).ConfigureAwait(false); if (addChatParticipantsResult.Value.InvalidParticipants.Count > 0) { - throw _clientDiagnostics.CreateRequestFailedException(addChatParticipantsResult.GetRawResponse()); + throw new RequestFailedException(addChatParticipantsResult.GetRawResponse()); } return addChatParticipantsResult.GetRawResponse(); } @@ -452,7 +452,7 @@ public virtual Response AddParticipant(ChatParticipant participant, Cancellation Response addChatParticipantsResult = _chatThreadRestClient.AddChatParticipants(Id, new[] { participant.ToChatParticipantInternal() }, cancellationToken); if (addChatParticipantsResult.Value.InvalidParticipants.Count > 0) { - throw _clientDiagnostics.CreateRequestFailedException(addChatParticipantsResult.GetRawResponse()); + throw new RequestFailedException(addChatParticipantsResult.GetRawResponse()); } return addChatParticipantsResult.GetRawResponse(); } diff --git a/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/SipRoutingRestClient.cs b/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/SipRoutingRestClient.cs index 89bc4570e109b..95285885e183d 100644 --- a/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/SipRoutingRestClient.cs +++ b/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/Generated/SipRoutingRestClient.cs @@ -68,7 +68,7 @@ public async Task> GetSipConfigurationAsync(Cancellat return Response.FromValue(value, message.Response); } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -88,7 +88,7 @@ public Response GetSipConfiguration(CancellationToken cancella return Response.FromValue(value, message.Response); } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/SipRoutingRestClient.cs b/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/SipRoutingRestClient.cs index 66f737fab4d22..685aadbfa8d89 100644 --- a/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/SipRoutingRestClient.cs +++ b/sdk/communication/Azure.Communication.PhoneNumbers/src/SipRouting/SipRoutingRestClient.cs @@ -54,7 +54,7 @@ public async Task UpdateAsync(SipConfiguration body = null, Cancellati return mappedResponse; } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -79,7 +79,7 @@ public Response Update(SipConfiguration body = null, CancellationToken cancellat return mappedResponse; } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/Azure.Security.ConfidentialLedger.csproj b/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/Azure.Security.ConfidentialLedger.csproj index 033bc30cee715..4352f475967f7 100644 --- a/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/Azure.Security.ConfidentialLedger.csproj +++ b/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/Azure.Security.ConfidentialLedger.csproj @@ -16,6 +16,9 @@ + + + diff --git a/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs b/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs index e8b73356dbd8a..75d0381ee8778 100644 --- a/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs +++ b/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs @@ -64,9 +64,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella if (statusResponse.Status != (int)HttpStatusCode.OK) { var error = new ResponseError(null, exceptionMessage); - var ex = async - ? await _client.ClientDiagnostics.CreateRequestFailedExceptionAsync(statusResponse, error).ConfigureAwait(false) - : _client.ClientDiagnostics.CreateRequestFailedException(statusResponse, error); + var ex = new RequestFailedException(statusResponse, null, error); return OperationState.Failure(statusResponse, new RequestFailedException(exceptionMessage, ex)); } diff --git a/sdk/core/Azure.Core/src/Pipeline/RequestFailedDetailsParser.cs b/sdk/core/Azure.Core/src/Pipeline/RequestFailedDetailsParser.cs index 46c0ddb4ddefe..5779d8da6a02c 100644 --- a/sdk/core/Azure.Core/src/Pipeline/RequestFailedDetailsParser.cs +++ b/sdk/core/Azure.Core/src/Pipeline/RequestFailedDetailsParser.cs @@ -14,7 +14,7 @@ public abstract class RequestFailedDetailsParser /// /// Parses the error details from the provided . /// - /// The to parse. + /// The to parse. The will already be buffered. /// The describing the parsed error details. /// Data to be applied to the property. /// true if successful, otherwise false. diff --git a/sdk/core/Azure.Core/src/RequestFailedException.cs b/sdk/core/Azure.Core/src/RequestFailedException.cs index bc293de3c27f2..986afe5ac16b7 100644 --- a/sdk/core/Azure.Core/src/RequestFailedException.cs +++ b/sdk/core/Azure.Core/src/RequestFailedException.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.IO; using System.Runtime.Serialization; @@ -38,6 +39,7 @@ public class RequestFailedException : Exception, ISerializable /// Initializes a new instance of the class with a specified error message. /// The message that describes the error. + [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(string message) : this(0, message) { } @@ -45,6 +47,7 @@ public RequestFailedException(string message) : this(0, message) /// Initializes a new instance of the class with a specified error message, HTTP status code and a reference to the inner exception that is the cause of this exception. /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. + [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(string message, Exception? innerException) : this(0, message, innerException) { } @@ -52,6 +55,7 @@ public RequestFailedException(string message, Exception? innerException) : this( /// Initializes a new instance of the class with a specified error message and HTTP status code. /// The HTTP status code, or 0 if not available. /// The message that describes the error. + [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(int status, string message) : this(status, message, null) { @@ -61,6 +65,7 @@ public RequestFailedException(int status, string message) /// The HTTP status code, or 0 if not available. /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. + [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(int status, string message, Exception? innerException) : this(status, message, null, innerException) { @@ -71,6 +76,7 @@ public RequestFailedException(int status, string message, Exception? innerExcept /// The error message that explains the reason for the exception. /// The service specific error code. /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. + [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(int status, string message, string? errorCode, Exception? innerException) : base(message, innerException) { @@ -108,7 +114,18 @@ public RequestFailedException(Response response) /// The response to obtain error details from. /// An inner exception to associate with the new . public RequestFailedException(Response response, Exception? innerException) - : this(response.Status, GetRequestFailedExceptionContent(response), innerException) + : this(response, innerException, null) + { + } + + /// Initializes a new instance of the class + /// with an error message, HTTP status code, error code obtained from the specified response. + /// The response to obtain error details from. + /// An inner exception to associate with the new . + /// The error information to use when constructing the exception message. If null, this will be parsed from the Response body. + /// Additional information to include in the exception message. This will also be stored in the property. + public RequestFailedException(Response response, Exception? innerException, ResponseError? error, IDictionary? additionalInfo = null) + : this(response.Status, GetRequestFailedExceptionContent(response, error, additionalInfo), innerException) { _response = response; } @@ -137,11 +154,20 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont /// public Response? GetRawResponse() => _response; - internal static (string FormattedError, string? ErrorCode, IDictionary? Data) GetRequestFailedExceptionContent(Response response) + internal static (string FormattedError, string? ErrorCode, IDictionary? Data) GetRequestFailedExceptionContent(Response response, ResponseError? error, IDictionary? additionalInfo) { BufferResponseIfNeeded(response); - bool parseSuccess = response.RequestFailedDetailsParser == null ? TryExtractErrorContent(response, out ResponseError? error, out IDictionary? data) : response.RequestFailedDetailsParser.TryParse(response, out error, out data); + // only attempt to parse the error and additional info if not already provided. + if (error == null && additionalInfo == null) + { + bool parseSuccess = response.RequestFailedDetailsParser == null ? TryExtractErrorContent(response, out error, out additionalInfo) : response.RequestFailedDetailsParser.TryParse(response, out error, out additionalInfo); + if (!parseSuccess) + { + error = null; + additionalInfo = null; + } + } StringBuilder messageBuilder = new(); messageBuilder @@ -167,12 +193,12 @@ internal static (string FormattedError, string? ErrorCode, IDictionary 0) + if (additionalInfo is { Count: > 0 }) { messageBuilder .AppendLine() .AppendLine("Additional Information:"); - foreach (KeyValuePair info in data) + foreach (KeyValuePair info in additionalInfo) { messageBuilder .Append(info.Key) @@ -201,7 +227,7 @@ internal static (string FormattedError, string? ErrorCode, IDictionary>> AddAsync( return Response.FromValue(value, message.Response); } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -70,7 +70,7 @@ internal Response> Add( return Response.FromValue(value, message.Response); } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -96,7 +96,7 @@ internal async Task UpdateAsync( return message.Response.Status switch { 204 => message.Response, - _ => throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false), + _ => throw new RequestFailedException(message.Response), }; } @@ -122,7 +122,7 @@ internal Response Update( return message.Response.Status switch { 204 => message.Response, - _ => throw ClientDiagnostics.CreateRequestFailedException(message.Response), + _ => throw new RequestFailedException(message.Response), }; } diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs index 4ecb1288c11ec..06d7547059c5c 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs @@ -77,7 +77,7 @@ internal async Task> AddAsync( return Response.FromValue(null, message.Response); default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -109,7 +109,7 @@ internal Response Add( return Response.FromValue(null, message.Response); default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -137,7 +137,7 @@ internal async Task UpdateAsync( return message.Response; default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -165,7 +165,7 @@ internal Response Update( return message.Response; default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -199,7 +199,7 @@ internal async Task> AddRelationshipAsync( return Response.FromValue(value, message.Response); } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -233,7 +233,7 @@ public Response AddRelationship( return Response.FromValue(value, message.Response); } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -258,7 +258,7 @@ internal async Task UpdateRelationshipAsync( return message.Response.Status switch { 204 => message.Response, - _ => throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false), + _ => throw new RequestFailedException(message.Response), }; } @@ -283,7 +283,7 @@ internal Response UpdateRelationship( return message.Response.Status switch { 204 => message.Response, - _ => throw ClientDiagnostics.CreateRequestFailedException(message.Response), + _ => throw new RequestFailedException(message.Response), }; } @@ -312,7 +312,7 @@ internal async Task UpdateComponentAsync( return message.Response; default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -341,7 +341,7 @@ internal Response UpdateComponent( return message.Response; default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -373,7 +373,7 @@ internal async Task SendTelemetryAsync( return message.Response; default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -405,7 +405,7 @@ internal Response SendTelemetry( return message.Response; default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -442,7 +442,7 @@ internal async Task SendComponentTelemetryAsync( return message.Response; default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -479,7 +479,7 @@ internal Response SendComponentTelemetry( return message.Response; default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -511,7 +511,7 @@ internal async Task>> ListRelationshipsAsync< return Response.FromValue(value, message.Response); } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -549,7 +549,7 @@ internal async Task>> ListRelationshipsNextPa return Response.FromValue(value, message.Response); } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -581,7 +581,7 @@ internal Response> ListRelationships( return Response.FromValue(value, message.Response); } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -619,7 +619,7 @@ internal Response> ListRelationshipsNextPage( return Response.FromValue(value, message.Response); } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/QueryRestClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/QueryRestClient.cs index 9602697e14b26..96517d9b7f785 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/QueryRestClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/QueryRestClient.cs @@ -40,7 +40,7 @@ internal async Task, QueryQueryTwinsHeaders>> return ResponseWithHeaders.FromValue(value, headers, message.Response); } default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -72,7 +72,7 @@ internal ResponseWithHeaders, QueryQueryTwinsHeaders> QueryTwins< return ResponseWithHeaders.FromValue(value, headers, message.Response); } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/src/EventGridPublisherClient.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/src/EventGridPublisherClient.cs index 023d0f67b50fb..57f581bbc528d 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/src/EventGridPublisherClient.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/src/EventGridPublisherClient.cs @@ -121,9 +121,7 @@ private async Task SendCloudNativeCloudEventsInternalAsync(ReadOnlyMem return message.Response.Status switch { 200 => message.Response, - _ => async ? - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - throw _clientDiagnostics.CreateRequestFailedException(message.Response) + _ => throw new RequestFailedException(message.Response) }; } catch (Exception e) @@ -190,9 +188,7 @@ private async Task SendEventsInternal(IEnumerable even return message.Response.Status switch { 200 => message.Response, - _ => async ? - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - throw _clientDiagnostics.CreateRequestFailedException(message.Response) + _ => throw new RequestFailedException(message.Response) }; } catch (Exception e) @@ -294,9 +290,7 @@ private async Task SendCloudEventsInternal(IEnumerable eve return message.Response.Status switch { 200 => message.Response, - _ => async ? - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - throw _clientDiagnostics.CreateRequestFailedException(message.Response) + _ => throw new RequestFailedException(message.Response) }; } catch (Exception e) @@ -364,9 +358,7 @@ private async Task PublishCustomEventsInternal(IEnumerable return message.Response.Status switch { 200 => message.Response, - _ => async ? - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false) : - throw _clientDiagnostics.CreateRequestFailedException(message.Response) + _ => throw new RequestFailedException(message.Response) }; } catch (Exception e) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/Azure.AI.FormRecognizer.sln b/sdk/formrecognizer/Azure.AI.FormRecognizer/Azure.AI.FormRecognizer.sln index f60d4ed4b326c..1b09b9e198fec 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/Azure.AI.FormRecognizer.sln +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/Azure.AI.FormRecognizer.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\.. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.FormRecognizer.Perf", "perf\Azure.AI.FormRecognizer.Perf\Azure.AI.FormRecognizer.Perf.csproj", "{E11C4DF2-C78A-4EE3-B3FC-BE4F7C7A80F1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core", "..\..\core\Azure.Core\src\Azure.Core.csproj", "{835A88E0-375D-4403-B2FF-206187559302}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,6 +45,10 @@ Global {6C5E5550-A9AE-4B52-84E5-32E035AC4D40}.Debug|Any CPU.Build.0 = Debug|Any CPU {6C5E5550-A9AE-4B52-84E5-32E035AC4D40}.Release|Any CPU.ActiveCfg = Release|Any CPU {6C5E5550-A9AE-4B52-84E5-32E035AC4D40}.Release|Any CPU.Build.0 = Release|Any CPU + {835A88E0-375D-4403-B2FF-206187559302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {835A88E0-375D-4403-B2FF-206187559302}.Debug|Any CPU.Build.0 = Debug|Any CPU + {835A88E0-375D-4403-B2FF-206187559302}.Release|Any CPU.ActiveCfg = Release|Any CPU + {835A88E0-375D-4403-B2FF-206187559302}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/AnalyzeDocumentOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/AnalyzeDocumentOperation.cs index 811bac209741b..4edd2e9ca636d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/AnalyzeDocumentOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/AnalyzeDocumentOperation.cs @@ -197,9 +197,7 @@ async ValueTask> IOperation.UpdateS } else if (status == AnalyzeResultOperationStatus.Failed) { - RequestFailedException requestFailedException = await ClientCommon - .CreateExceptionForFailedOperationAsync(async, _diagnostics, rawResponse, response.Value.Error) - .ConfigureAwait(false); + RequestFailedException requestFailedException = ClientCommon.CreateExceptionForFailedOperation(rawResponse, response.Value.Error); return OperationState.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Azure.AI.FormRecognizer.csproj b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Azure.AI.FormRecognizer.csproj index 74b0d3e038f98..5f9e372b94a11 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Azure.AI.FormRecognizer.csproj +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Azure.AI.FormRecognizer.csproj @@ -12,6 +12,9 @@ + + + diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentClassifierOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentClassifierOperation.cs index 09994a0332007..b4ab1552cd077 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentClassifierOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentClassifierOperation.cs @@ -182,9 +182,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentModelOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentModelOperation.cs index 0a56afd8b2af1..fc64452bb4c09 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentModelOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildDocumentModelOperation.cs @@ -182,9 +182,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ClassifyDocumentOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ClassifyDocumentOperation.cs index acef99aee39dc..c62ab47990cb1 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ClassifyDocumentOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ClassifyDocumentOperation.cs @@ -185,9 +185,7 @@ async ValueTask> IOperation.UpdateS } else if (status == AnalyzeResultOperationStatus.Failed) { - RequestFailedException requestFailedException = await ClientCommon - .CreateExceptionForFailedOperationAsync(async, _diagnostics, rawResponse, response.Value.Error) - .ConfigureAwait(false); + RequestFailedException requestFailedException = ClientCommon.CreateExceptionForFailedOperation(rawResponse, response.Value.Error); return OperationState.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ComposeDocumentModelOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ComposeDocumentModelOperation.cs index 051a7fbf76c79..bbbc91b59d561 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ComposeDocumentModelOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ComposeDocumentModelOperation.cs @@ -182,9 +182,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CopyDocumentModelToOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CopyDocumentModelToOperation.cs index 8d02be5876eb5..99b5c296b7d52 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CopyDocumentModelToOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CopyDocumentModelToOperation.cs @@ -187,9 +187,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeBusinessCardsOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeBusinessCardsOperation.cs index 903a21a759cf2..f5dca714914ec 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeBusinessCardsOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeBusinessCardsOperation.cs @@ -164,9 +164,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeContentOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeContentOperation.cs index abc7ef2dc92b4..0a0ab301a0ad8 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeContentOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeContentOperation.cs @@ -165,9 +165,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeCustomFormsOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeCustomFormsOperation.cs index 39a5ca8a7ff29..5f1f2adbb37e7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeCustomFormsOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeCustomFormsOperation.cs @@ -198,9 +198,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeIdentityDocumentsOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeIdentityDocumentsOperation.cs index f072490db91ca..ab8b2abd681fd 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeIdentityDocumentsOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeIdentityDocumentsOperation.cs @@ -163,9 +163,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeInvoicesOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeInvoicesOperation.cs index a3d46e8a1121e..e244ce294a0bd 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeInvoicesOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeInvoicesOperation.cs @@ -164,9 +164,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeReceiptsOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeReceiptsOperation.cs index 80bedebd64935..94e0813907ed8 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeReceiptsOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/RecognizeReceiptsOperation.cs @@ -163,9 +163,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CopyModelOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CopyModelOperation.cs index dd7c656ddf4cb..2bf49ebfe64db 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CopyModelOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CopyModelOperation.cs @@ -197,9 +197,7 @@ async ValueTask> IOperation.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CreateCustomFormModelOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CreateCustomFormModelOperation.cs index d5f49bd8b2318..4653a3ac9371c 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CreateCustomFormModelOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient/CreateCustomFormModelOperation.cs @@ -165,12 +165,10 @@ async ValueTask> IOperation.Upd } else if (status == CustomFormModelStatus.Invalid) { - RequestFailedException requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync( - async, - _diagnostics, - rawResponse, - response.Value.TrainResult.Errors, - $"Invalid model created with ID {response.Value.ModelInfo.ModelId}").ConfigureAwait(false); + RequestFailedException requestFailedException = ClientCommon.CreateExceptionForFailedOperation( + rawResponse, + response.Value.TrainResult.Errors, + $"Invalid model created with ID {response.Value.ModelInfo.ModelId}"); return OperationState.Failure(rawResponse, requestFailedException); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs index 3287fe3ad7c41..e5eefbca3649c 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs @@ -49,7 +49,7 @@ public static string GetResponseHeader(ResponseHeaders responseHeaders, string h } } - public static async ValueTask CreateExceptionForFailedOperationAsync(bool async, ClientDiagnostics diagnostics, Response response, IReadOnlyList errors, string errorMessage = default) + public static RequestFailedException CreateExceptionForFailedOperation(Response response, IReadOnlyList errors, string errorMessage = default) { string errorCode = default; @@ -68,17 +68,13 @@ public static async ValueTask CreateExceptionForFailedOp } var responseError = new ResponseError(errorCode, errorMessage); - return async - ? await diagnostics.CreateRequestFailedExceptionAsync(response, responseError, errorInfo).ConfigureAwait(false) - : diagnostics.CreateRequestFailedException(response, responseError, errorInfo); + return new RequestFailedException(response, null, responseError, errorInfo); } - public static async ValueTask CreateExceptionForFailedOperationAsync(bool async, ClientDiagnostics diagnostics, Response response, ResponseError error) + public static RequestFailedException CreateExceptionForFailedOperation(Response response, ResponseError error) { var additionalInfo = new Dictionary(1) { { "AdditionInformation", error.ToString() } }; - return async - ? await diagnostics.CreateRequestFailedExceptionAsync(response, error, additionalInfo).ConfigureAwait(false) - : diagnostics.CreateRequestFailedException(response, error, additionalInfo); + return new RequestFailedException(response, null, error, additionalInfo); } public static RecognizedFormCollection ConvertPrebuiltOutputToRecognizedForms(V2AnalyzeResult analyzeResult) diff --git a/sdk/identity/Azure.Identity.sln b/sdk/identity/Azure.Identity.sln index 1f6ea6a1991fd..e7addc6a1628e 100644 --- a/sdk/identity/Azure.Identity.sln +++ b/sdk/identity/Azure.Identity.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Identity.BrokeredAuth EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Identity.BrokeredAuthentication.Tests", "Azure.Identity.BrokeredAuthentication\tests\Azure.Identity.BrokeredAuthentication.Tests.csproj", "{5F72962A-E4A5-4DBD-BA00-AB5B7725CACA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core", "..\core\Azure.Core\src\Azure.Core.csproj", "{B8BF1ED4-DD68-4504-9060-008D1A980958}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {5F72962A-E4A5-4DBD-BA00-AB5B7725CACA}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F72962A-E4A5-4DBD-BA00-AB5B7725CACA}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F72962A-E4A5-4DBD-BA00-AB5B7725CACA}.Release|Any CPU.Build.0 = Release|Any CPU + {B8BF1ED4-DD68-4504-9060-008D1A980958}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8BF1ED4-DD68-4504-9060-008D1A980958}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8BF1ED4-DD68-4504-9060-008D1A980958}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8BF1ED4-DD68-4504-9060-008D1A980958}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/identity/Azure.Identity/src/Azure.Identity.csproj b/sdk/identity/Azure.Identity/src/Azure.Identity.csproj index bc63692ed8f6b..6d3a20bdb1d12 100644 --- a/sdk/identity/Azure.Identity/src/Azure.Identity.csproj +++ b/sdk/identity/Azure.Identity/src/Azure.Identity.csproj @@ -11,7 +11,10 @@ true - + + + + diff --git a/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs b/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs index fb54637b957d4..1291307c8b168 100644 --- a/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs +++ b/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs @@ -120,7 +120,7 @@ protected override async ValueTask HandleResponseAsync(bool async, if (baseMessage != null) { - string message = await Pipeline.Diagnostics.CreateRequestFailedMessageAsync(response, new ResponseError(null, baseMessage), null, async).ConfigureAwait(false); + string message = new RequestFailedException(response, null, new ResponseError(null, baseMessage)).Message; var errorContentMessage = await GetMessageFromResponse(response, async, cancellationToken).ConfigureAwait(false); diff --git a/sdk/iot/Azure.IoT.Hub.Service/src/Customized/JobsRestClient.cs b/sdk/iot/Azure.IoT.Hub.Service/src/Customized/JobsRestClient.cs index eee204efd35b6..27e21bdc6dd44 100644 --- a/sdk/iot/Azure.IoT.Hub.Service/src/Customized/JobsRestClient.cs +++ b/sdk/iot/Azure.IoT.Hub.Service/src/Customized/JobsRestClient.cs @@ -40,7 +40,7 @@ internal Response CancelImportExportJob(string id, CancellationToken can return Response.FromValue(null, message.Response); default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -73,7 +73,7 @@ internal async Task> CancelImportExportJobAsync(string id, Canc return Response.FromValue(null, message.Response); default: - throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } diff --git a/sdk/modelsrepository/Azure.IoT.ModelsRepository/src/Fetchers/HttpModelFetcher.cs b/sdk/modelsrepository/Azure.IoT.ModelsRepository/src/Fetchers/HttpModelFetcher.cs index bf388d2c427bc..f14f06ac7dfed 100644 --- a/sdk/modelsrepository/Azure.IoT.ModelsRepository/src/Fetchers/HttpModelFetcher.cs +++ b/sdk/modelsrepository/Azure.IoT.ModelsRepository/src/Fetchers/HttpModelFetcher.cs @@ -175,7 +175,7 @@ private string EvaluatePath(string path, CancellationToken cancellationToken = d return GetContent(message.Response.ContentStream); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception ex) @@ -203,7 +203,7 @@ private async Task EvaluatePathAsync(string path, CancellationToken canc return await GetContentAsync(message.Response.ContentStream, cancellationToken).ConfigureAwait(false); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } catch (Exception ex) diff --git a/sdk/monitor/Azure.Monitor.Query/src/LogsQueryClient.cs b/sdk/monitor/Azure.Monitor.Query/src/LogsQueryClient.cs index fe07e2f76e3b8..dc0ee7eccf8ba 100644 --- a/sdk/monitor/Azure.Monitor.Query/src/LogsQueryClient.cs +++ b/sdk/monitor/Azure.Monitor.Query/src/LogsQueryClient.cs @@ -719,14 +719,7 @@ Response ConvertBatchResponse(BatchResponse resp } default: { - if (async) - { - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - else - { - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } + throw new RequestFailedException(message.Response); } } } @@ -780,14 +773,7 @@ await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellat } default: { - if (async) - { - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - else - { - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/monitor/Azure.Monitor.Query/tests/LogSenderClient.cs b/sdk/monitor/Azure.Monitor.Query/tests/LogSenderClient.cs index 1083b179971f6..9ff7800d6c54e 100644 --- a/sdk/monitor/Azure.Monitor.Query/tests/LogSenderClient.cs +++ b/sdk/monitor/Azure.Monitor.Query/tests/LogSenderClient.cs @@ -53,7 +53,7 @@ public async Task SendAsync(string tableName, IEnumerable SendAsync(object data) var response = await _pipeline.SendRequestAsync(request, default); if (response.Status != 200) { - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response); + throw new RequestFailedException(response); } return response; diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EvaluationsRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EvaluationsRestClient.cs index 4e8df6d96cdc8..8e165cac48fa2 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EvaluationsRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EvaluationsRestClient.cs @@ -66,7 +66,7 @@ public async Task DeleteAsync(string evaluationId, CancellationToken c case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -88,7 +88,7 @@ public Response Delete(string evaluationId, CancellationToken cancellationToken case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -130,7 +130,7 @@ public async Task> GetAsync(string evaluationId return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -157,7 +157,7 @@ public Response Get(string evaluationId, CancellationTok return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -196,7 +196,7 @@ public async Task>> ListAsync(Can return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -221,7 +221,7 @@ public Response> List(CancellationToken ca return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -267,7 +267,7 @@ public async Task Cre return ResponseWithHeaders.FromValue(value, headers, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EventsRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EventsRestClient.cs index 255dc118a554b..a8e45fd2d6bbd 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EventsRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/EventsRestClient.cs @@ -75,7 +75,7 @@ public async Task RewardAsync(string eventId, PersonalizerRewardOption case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -102,7 +102,7 @@ public Response Reward(string eventId, PersonalizerRewardOptions reward, Cancell case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -140,7 +140,7 @@ public async Task ActivateAsync(string eventId, CancellationToken canc case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -162,7 +162,7 @@ public Response Activate(string eventId, CancellationToken cancellationToken = d case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/LogRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/LogRestClient.cs index 33a6221ca3545..cb99251a61716 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/LogRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/LogRestClient.cs @@ -57,7 +57,7 @@ public async Task DeleteAsync(CancellationToken cancellationToken = de case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -72,7 +72,7 @@ public Response Delete(CancellationToken cancellationToken = default) case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -106,7 +106,7 @@ public async Task> GetPropertiesAsync(Cancel return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -126,7 +126,7 @@ public Response GetProperties(CancellationToken cance return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ModelRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ModelRestClient.cs index 8e41037f85e5e..a99fa0f9f67cc 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ModelRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ModelRestClient.cs @@ -67,7 +67,7 @@ public async Task> GetAsync(bool? signed = null, CancellationTo return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -86,7 +86,7 @@ public Response Get(bool? signed = null, CancellationToken cancellationT return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -124,7 +124,7 @@ public async Task ImportAsync(Stream body, CancellationToken cancellat case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -146,7 +146,7 @@ public Response Import(Stream body, CancellationToken cancellationToken = defaul case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -175,7 +175,7 @@ public async Task ResetAsync(CancellationToken cancellationToken = def case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -190,7 +190,7 @@ public Response Reset(CancellationToken cancellationToken = default) case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -224,7 +224,7 @@ public async Task> GetPropertiesAsync(Canc return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -244,7 +244,7 @@ public Response GetProperties(CancellationToken can return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotEventsRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotEventsRestClient.cs index 2c935101ff06e..a8a395ea31541 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotEventsRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotEventsRestClient.cs @@ -75,7 +75,7 @@ public async Task RewardAsync(string eventId, PersonalizerRewardMultiS case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -102,7 +102,7 @@ public Response Reward(string eventId, PersonalizerRewardMultiSlotOptions body, case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -140,7 +140,7 @@ public async Task ActivateAsync(string eventId, CancellationToken canc case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -162,7 +162,7 @@ public Response Activate(string eventId, CancellationToken cancellationToken = d case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotRestClient.cs index c001a8ef77ceb..8f50c66e56e98 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/MultiSlotRestClient.cs @@ -74,7 +74,7 @@ public async Task> RankAsync(Personali return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -101,7 +101,7 @@ public Response Rank(PersonalizerRankMultiSlotO return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/PolicyRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/PolicyRestClient.cs index fd3c936e584a3..c97ae73ce4461 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/PolicyRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/PolicyRestClient.cs @@ -63,7 +63,7 @@ public async Task> GetAsync(CancellationToken cance return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -83,7 +83,7 @@ public Response Get(CancellationToken cancellationToken = de return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -128,7 +128,7 @@ public async Task> UpdateAsync(PersonalizerPolicy p return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -155,7 +155,7 @@ public Response Update(PersonalizerPolicy policy, Cancellati return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -189,7 +189,7 @@ public async Task> ResetAsync(CancellationToken can return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -209,7 +209,7 @@ public Response Reset(CancellationToken cancellationToken = return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/RankRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/RankRestClient.cs index 24a0be61d7ec2..a3067a12e61d8 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/RankRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/RankRestClient.cs @@ -74,7 +74,7 @@ public async Task> RankAsync(PersonalizerRankOp return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -101,7 +101,7 @@ public Response Rank(PersonalizerRankOptions rankRequest return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ServiceConfigurationRestClient.cs b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ServiceConfigurationRestClient.cs index 72fff9d81e1c2..a62932f9083b7 100644 --- a/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ServiceConfigurationRestClient.cs +++ b/sdk/personalizer/Azure.AI.Personalizer/src/Generated/ServiceConfigurationRestClient.cs @@ -74,7 +74,7 @@ public async Task> UpdateAsync(Personali return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -101,7 +101,7 @@ public Response Update(PersonalizerServicePropert return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -135,7 +135,7 @@ public async Task> GetAsync(Cancellation return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -155,7 +155,7 @@ public Response Get(CancellationToken cancellatio return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -195,7 +195,7 @@ public async Task ApplyFromEvaluationAsync(PersonalizerPolicyReference case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -217,7 +217,7 @@ public Response ApplyFromEvaluation(PersonalizerPolicyReferenceOptions body, Can case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs index dc800f8519a03..34bf2f6273800 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs @@ -41,13 +41,13 @@ public HttpRequestAndResponse( _port = GetPort(_fullyQualifiedNamespace); } - internal async Task ThrowIfRequestFailedAsync(Request request, Response response) + internal void ThrowIfRequestFailedAsync(Request request, Response response) { if ((response.Status >= 200) && (response.Status < 400)) { return; } - RequestFailedException ex = await _diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false); + RequestFailedException ex = new RequestFailedException(response); if (response.Status == (int)HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException( @@ -274,7 +274,7 @@ private async Task SendHttpRequestAsync( Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - await ThrowIfRequestFailedAsync(request, response).ConfigureAwait(false); + ThrowIfRequestFailedAsync(request, response); return response; } diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs index 41f551ac6f047..d47c8f9f08919 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs @@ -33,7 +33,7 @@ public static async Task ParseResponseAsync(Response respon throw new ServiceBusException( false, "Unknown error.", - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) @@ -48,7 +48,7 @@ private static async Task ParseFromEntryElementAsync(XEleme throw new ServiceBusException( false, "Unknown error.", - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } foreach (var element in nsInfoXml.Elements()) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs index 79e21e4b728a2..94f5559406d2d 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs @@ -78,7 +78,7 @@ public static async Task ParseResponseAsync(Response response, throw new ServiceBusException( "Queue was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) @@ -93,7 +93,7 @@ private static async Task ParseFromEntryElementAsync(XElement x throw new ServiceBusException( "Queue was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } var properties = new QueueProperties(name); @@ -223,7 +223,7 @@ public static async Task> ParsePagedResponseAsync(Response throw new ServiceBusException( "No queues were found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } public static void NormalizeDescription(this QueueProperties description, string baseAddress) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs index c70bdc2e40572..f5af8e7791057 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs @@ -34,7 +34,7 @@ public static async Task ParseResponseAsync(Response res throw new ServiceBusException( "Queue was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) @@ -50,7 +50,7 @@ private static async Task ParseFromEntryElementAsync(XEl throw new ServiceBusException( "Queue was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } foreach (var element in qdXml.Elements()) @@ -131,7 +131,7 @@ public static async Task> ParsePagedResponseAsync(R throw new ServiceBusException( "No queues were found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } } } diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/Rules/RuleDescriptionExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/Rules/RuleDescriptionExtensions.cs index b193378ed2709..3651e81dda713 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/Rules/RuleDescriptionExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/Rules/RuleDescriptionExtensions.cs @@ -64,7 +64,7 @@ public static async Task ParseResponseAsync(Response response, C throw new ServiceBusException( "Rule was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } public static async Task> ParsePagedResponseAsync(Response response, ClientDiagnostics diagnostics) @@ -96,7 +96,7 @@ public static async Task> ParsePagedResponseAsync(Response throw new ServiceBusException( "Rule was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } private static RuleProperties ParseFromEntryElement(XElement xEntry) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs index 1f5c3fa939ee4..81b0b63942f33 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs @@ -59,7 +59,7 @@ public static async Task ParseResponseAsync(string topic throw new ServiceBusException( "Subscription was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } public static async Task> ParsePagedResponseAsync(string topicName, Response response, ClientDiagnostics diagnostics) @@ -92,7 +92,7 @@ public static async Task> ParsePagedResponseAsync(s throw new ServiceBusException( "No subscriptions were found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } private static async Task ParseFromEntryElementAsync(string topicName, XElement xEntry, Response response, ClientDiagnostics diagnostics) @@ -108,7 +108,7 @@ private static async Task ParseFromEntryElementAsync(str throw new ServiceBusException( "Subscription was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } foreach (var element in subscriptionXml.Elements()) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs index 2ee036bff0e03..a85ed15a1b6f1 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs @@ -22,7 +22,7 @@ public static async Task ParseResponseAsync(strin { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(topicName, xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(topicName, xDoc, response, diagnostics); } } } @@ -34,10 +34,10 @@ public static async Task ParseResponseAsync(strin throw new ServiceBusException( "Subscription was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } - private static async Task ParseFromEntryElementAsync(string topicName, XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static void SubscriptionRuntimeProperties ParseFromEntryElement(string topicName, XElement xEntry, Response response, ClientDiagnostics diagnostics) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; var subscriptionRuntimeInfo = new SubscriptionRuntimeProperties(topicName, name); @@ -50,7 +50,7 @@ private static async Task ParseFromEntryElementAs throw new ServiceBusException( "Subscription was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } foreach (var element in qdXml.Elements()) @@ -110,7 +110,7 @@ public static async Task> ParsePagedResponse var entryList = xDoc.Elements(XName.Get("entry", AdministrationClientConstants.AtomNamespace)); foreach (var entry in entryList) { - subscriptionList.Add(await ParseFromEntryElementAsync(topicPath, entry, response, diagnostics).ConfigureAwait(false)); + subscriptionList.Add(ParseFromEntryElement(topicPath, entry, response, diagnostics)); } return subscriptionList; @@ -125,7 +125,7 @@ public static async Task> ParsePagedResponse throw new ServiceBusException( "No subscriptions were found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } } } diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs index 5a5ac87fa00dd..64e8b3a871a88 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs @@ -35,7 +35,7 @@ public static async Task ParseResponseAsync(Response response, throw new ServiceBusException( "Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } public static async Task> ParsePagedResponseAsync(Response response, ClientDiagnostics diagnostics) @@ -68,7 +68,7 @@ public static async Task> ParsePagedResponseAsync(Response throw new ServiceBusException( "No topics were found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) @@ -82,7 +82,7 @@ private static async Task ParseFromEntryElementAsync(XElement x throw new ServiceBusException( "Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } var topicProperties = new TopicProperties(name); diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs index 65c5d82c07079..a3fd5aa93209b 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs @@ -34,7 +34,7 @@ public static async Task ParseResponseAsync(Response res throw new ServiceBusException( "Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } public static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) @@ -50,7 +50,7 @@ public static async Task ParseFromEntryElementAsync(XEle throw new ServiceBusException( "Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } foreach (var element in qdXml.Elements()) @@ -120,7 +120,7 @@ public static async Task> ParsePagedResponseAsync(R throw new ServiceBusException( "No topics were found", ServiceBusFailureReason.MessagingEntityNotFound, - innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false)); + innerException: new RequestFailedException(response)); } } } diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/src/Azure.Storage.Blobs.Batch.csproj b/sdk/storage/Azure.Storage.Blobs.Batch/src/Azure.Storage.Blobs.Batch.csproj index e4162cc20a687..978f78f1ef0b1 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/src/Azure.Storage.Blobs.Batch.csproj +++ b/sdk/storage/Azure.Storage.Blobs.Batch/src/Azure.Storage.Blobs.Batch.csproj @@ -23,6 +23,9 @@ + + + diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs b/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs index ebf6bab9c786f..ea364946110c1 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs +++ b/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs @@ -48,6 +48,6 @@ public static InvalidOperationException InvalidHttpHeaderLine(string headerLine) new InvalidOperationException($"Expected an HTTP header line, not {headerLine}"); public static RequestFailedException InvalidResponse(ClientDiagnostics clientDiagnostics, Response response, Exception innerException) => - clientDiagnostics.CreateRequestFailedException(response, new ResponseError(null, "Invalid response"), innerException: innerException); + new RequestFailedException(response, innerException, new ResponseError(null, "Invalid response")); } } diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatch.cs b/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatch.cs index 5abe31b16f5f7..3a62b8d7f2d85 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatch.cs +++ b/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatch.cs @@ -216,7 +216,7 @@ public virtual Response DeleteBlob( return new DelayedResponse( message, - async response => + response => { switch (response.Status) { @@ -224,7 +224,7 @@ public virtual Response DeleteBlob( BlobDeleteHeaders blobDeleteHeaders = new BlobDeleteHeaders(response); return ResponseWithHeaders.FromValue(blobDeleteHeaders, response); default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false); + throw new RequestFailedException(response); } }); } @@ -327,7 +327,7 @@ public virtual Response SetBlobAccessTier( return new DelayedResponse( message, - async response => + response => { switch (response.Status) { @@ -336,7 +336,7 @@ public virtual Response SetBlobAccessTier( BlobSetAccessTierHeaders blobSetAccessTierHeaders = new BlobSetAccessTierHeaders(response); return ResponseWithHeaders.FromValue(blobSetAccessTierHeaders, response); default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false); + throw new RequestFailedException(response); } }); } diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatchClient.cs b/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatchClient.cs index 83177317b2562..9d61ea16aefd5 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatchClient.cs +++ b/sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatchClient.cs @@ -576,7 +576,7 @@ private async ValueTask UpdateOperationResponses( { // We'll re-process this response as a batch result - throw ClientDiagnostics.CreateRequestFailedException(responses[0]); + throw new RequestFailedException(responses[0]); } else { @@ -600,7 +600,7 @@ private async ValueTask UpdateOperationResponses( value is DelayedResponse response) { #pragma warning disable AZC0110 // DO NOT use await keyword in possibly synchronous scope. - await response.SetLiveResponse(responses[i], throwOnAnyFailure).ConfigureAwait(false); + response.SetLiveResponse(responses[i], throwOnAnyFailure); #pragma warning restore AZC0110 // DO NOT use await keyword in possibly synchronous scope. } } diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/src/DelayedResponse.cs b/sdk/storage/Azure.Storage.Blobs.Batch/src/DelayedResponse.cs index da1fd390997e9..b04f4e6c2ccf8 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/src/DelayedResponse.cs +++ b/sdk/storage/Azure.Storage.Blobs.Batch/src/DelayedResponse.cs @@ -30,7 +30,7 @@ internal class DelayedResponse : Response /// BlobRestClient.Group.OperationName_CreateResponse methods which /// correctly throw when necessary. /// - private readonly Func> _processResponse; + private readonly Func _processResponse; /// /// Gets the live Response or throws an InvalidOperationException if @@ -50,7 +50,7 @@ private Response LiveResponse /// An optional function that can be used to process the response. It /// is responsible for parsing response bodies and throwing exceptions. /// - public DelayedResponse(HttpMessage message, Func> processResponse = null) + public DelayedResponse(HttpMessage message, Func processResponse = null) { // Have the BatchPipelineTransport associate this response with the // message when it's sent. @@ -66,7 +66,7 @@ public DelayedResponse(HttpMessage message, Func> proce /// A value indicating whether or not we should throw for Response /// failures. /// - public async Task SetLiveResponse(Response live, bool throwOnFailure) + public void SetLiveResponse(Response live, bool throwOnFailure) { _live = live; @@ -74,7 +74,7 @@ public async Task SetLiveResponse(Response live, bool throwOnFailure) // tries to catch the exception but then interrogate raw responses if (throwOnFailure && _processResponse != null) { - _live = await _processResponse(_live).ConfigureAwait(false); + _live = _processResponse(_live); } } diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/tests/DelayedResponseTests.cs b/sdk/storage/Azure.Storage.Blobs.Batch/tests/DelayedResponseTests.cs index 5d9cf02bf536d..40124ed42675d 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/tests/DelayedResponseTests.cs +++ b/sdk/storage/Azure.Storage.Blobs.Batch/tests/DelayedResponseTests.cs @@ -19,10 +19,10 @@ public void DelayedResponseToStringDoesntThrow() } [Test] - public async Task CompletedDelayedResponseToStringCallsBase() + public void CompletedDelayedResponseToStringCallsBase() { DelayedResponse delayedResponse = new DelayedResponse(new HttpMessage(new MockRequest(), new ResponseClassifier())); - await delayedResponse.SetLiveResponse(new MockResponse(200, "Yay"), false); + delayedResponse.SetLiveResponse(new MockResponse(200, "Yay"), false); Assert.AreEqual("Status: 200, ReasonPhrase: Yay", delayedResponse.ToString()); } } diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/ErrorExtensions.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/ErrorExtensions.cs deleted file mode 100644 index a6cefbd4e7fcc..0000000000000 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/ErrorExtensions.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using System.Text.Json; -using System.Xml.Linq; -using Azure.Core.Pipeline; -using Azure.Storage.Files.DataLake.Models; - -namespace Azure.Storage.Files.DataLake -{ - internal static class ErrorExtensions - { -// clientDiagnostics parameter is a pattern expected by the codegenerator -#pragma warning disable CA1801 - internal static Exception CreateException(this string body, ClientDiagnostics clientDiagnostics, Response response) -#pragma warning restore CA1801 - { - // xml - if (response.Headers.ContentType != null - && response.Headers.ContentType.Contains("application/xml")) - { - XElement error = XDocument.Parse(body).Element("Error"); - string code = error.Element("Code").Value.ToString(CultureInfo.InvariantCulture); - string message = error.Element("Message").Value.ToString(CultureInfo.InvariantCulture); - return clientDiagnostics.CreateRequestFailedException( - response: response, - new ResponseError(code, message)); - } - // json - else if (response.Headers.ContentType != null - && response.Headers.ContentType.Contains("application/json")) - { - using JsonDocument json = JsonDocument.Parse(body); - JsonElement error = json.RootElement.GetProperty("error"); - - IDictionary details = default; - if (error.TryGetProperty("detail", out JsonElement detail)) - { - details = new Dictionary(); - foreach (JsonProperty property in detail.EnumerateObject()) - { - details[property.Name] = property.Value.GetString(); - } - } - - return clientDiagnostics.CreateRequestFailedException( - response: response, - new ResponseError( - error.GetProperty("code").GetString(), - error.GetProperty("message").GetString() - ), - additionalInfo: details); - } - else - { - return new RequestFailedException( - status: response.Status, - errorCode: response.Status.ToString(CultureInfo.InvariantCulture), - message: response.ReasonPhrase, - innerException: new Exception()); - } - } - } -} diff --git a/sdk/tables/Azure.Data.Tables/src/TableClient.cs b/sdk/tables/Azure.Data.Tables/src/TableClient.cs index 7c02a181c81aa..bdd69ef08971f 100644 --- a/sdk/tables/Azure.Data.Tables/src/TableClient.cs +++ b/sdk/tables/Azure.Data.Tables/src/TableClient.cs @@ -1355,7 +1355,7 @@ internal async Task DeleteEntityInternal( return message.Response.Status switch { 404 or 204 => message.Response, - _ => throw _diagnostics.CreateRequestFailedException(message.Response), + _ => throw new RequestFailedException(message.Response), }; } catch (Exception ex) diff --git a/sdk/tables/Azure.Data.Tables/src/TableRestClient.cs b/sdk/tables/Azure.Data.Tables/src/TableRestClient.cs index 48185045ec68d..040e621999330 100644 --- a/sdk/tables/Azure.Data.Tables/src/TableRestClient.cs +++ b/sdk/tables/Azure.Data.Tables/src/TableRestClient.cs @@ -124,7 +124,7 @@ public Response> SendBatchRequest(HttpMessage message, C throw ex; } default: - throw ClientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ApplicationsRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ApplicationsRestOperations.cs index 32fe759eab123..ad018ba5455d7 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ApplicationsRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ApplicationsRestOperations.cs @@ -93,7 +93,7 @@ public async Task> CreateAsync(ApplicationCreateParameters return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -120,7 +120,7 @@ public Response Create(ApplicationCreateParameters parameters, Canc return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -161,7 +161,7 @@ public async Task> ListAsync(string filter = nul return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -182,7 +182,7 @@ public Response List(string filter = null, CancellationTo return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -221,7 +221,7 @@ public async Task DeleteAsync(string applicationObjectId, Cancellation case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -243,7 +243,7 @@ public Response Delete(string applicationObjectId, CancellationToken cancellatio case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -287,7 +287,7 @@ public async Task> GetAsync(string applicationObjectId, Ca return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -314,7 +314,7 @@ public Response Get(string applicationObjectId, CancellationToken c return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -362,7 +362,7 @@ public async Task PatchAsync(string applicationObjectId, ApplicationUp case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -389,7 +389,7 @@ public Response Patch(string applicationObjectId, ApplicationUpdateParameters pa case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -434,7 +434,7 @@ public async Task> ListOwnersAsync(string ap return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -461,7 +461,7 @@ public Response ListOwners(string applicationObjectId return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -510,7 +510,7 @@ public async Task AddOwnerAsync(string applicationObjectId, AddOwnerPa case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -537,7 +537,7 @@ public Response AddOwner(string applicationObjectId, AddOwnerParameters paramete case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -583,7 +583,7 @@ public async Task RemoveOwnerAsync(string applicationObjectId, string case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -610,7 +610,7 @@ public Response RemoveOwner(string applicationObjectId, string ownerObjectId, Ca case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -655,7 +655,7 @@ public async Task> ListKeyCredentialsAsync(str return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -682,7 +682,7 @@ public Response ListKeyCredentials(string applicationOb return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -731,7 +731,7 @@ public async Task UpdateKeyCredentialsAsync(string applicationObjectId case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -758,7 +758,7 @@ public Response UpdateKeyCredentials(string applicationObjectId, KeyCredentialsU case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -803,7 +803,7 @@ public async Task> ListPasswordCredential return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -830,7 +830,7 @@ public Response ListPasswordCredentials(string app return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -879,7 +879,7 @@ public async Task UpdatePasswordCredentialsAsync(string applicationObj case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -906,7 +906,7 @@ public Response UpdatePasswordCredentials(string applicationObjectId, PasswordCr case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -951,7 +951,7 @@ public async Task> GetServicePrincipalsId return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -978,7 +978,7 @@ public Response GetServicePrincipalsIdByAppId(stri return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1022,7 +1022,7 @@ public async Task> ListNextAsync(string nextLink return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1049,7 +1049,7 @@ public Response ListNext(string nextLink, CancellationTok return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1094,7 +1094,7 @@ public async Task> ListOwnersNextPageAsync(s return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1126,7 +1126,7 @@ public Response ListOwnersNextPage(string nextLink, s return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1166,7 +1166,7 @@ public async Task> ListNextNextPageAsync(string return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1193,7 +1193,7 @@ public Response ListNextNextPage(string nextLink, Cancell return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DeletedApplicationsRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DeletedApplicationsRestOperations.cs index 0d70247929548..c4b74db85f6bf 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DeletedApplicationsRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DeletedApplicationsRestOperations.cs @@ -91,7 +91,7 @@ public async Task> RestoreAsync(string objectId, Cancellat return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -118,7 +118,7 @@ public Response Restore(string objectId, CancellationToken cancella return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -159,7 +159,7 @@ public async Task> ListAsync(string filter = nul return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -180,7 +180,7 @@ public Response List(string filter = null, CancellationTo return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -219,7 +219,7 @@ public async Task HardDeleteAsync(string applicationObjectId, Cancella case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -241,7 +241,7 @@ public Response HardDelete(string applicationObjectId, CancellationToken cancell case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -285,7 +285,7 @@ public async Task> ListNextAsync(string nextLink return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -312,7 +312,7 @@ public Response ListNext(string nextLink, CancellationTok return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -352,7 +352,7 @@ public async Task> ListNextNextPageAsync(string return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -379,7 +379,7 @@ public Response ListNextNextPage(string nextLink, Cancell return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DomainsRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DomainsRestOperations.cs index d37e3a61fb1eb..9b6036aaa0347 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DomainsRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/DomainsRestOperations.cs @@ -87,7 +87,7 @@ public async Task> ListAsync(string filter = null, Ca return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -108,7 +108,7 @@ public Response List(string filter = null, CancellationToken c return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -152,7 +152,7 @@ public async Task> GetAsync(string domainName, CancellationToke return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -179,7 +179,7 @@ public Response Get(string domainName, CancellationToken cancellationTok return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/GroupsRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/GroupsRestOperations.cs index 007133f29e50f..4fbcaf06e9cf0 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/GroupsRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/GroupsRestOperations.cs @@ -93,7 +93,7 @@ public async Task> IsMemberOfAsync(CheckGro return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -120,7 +120,7 @@ public Response IsMemberOf(CheckGroupMembershipParam return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -166,7 +166,7 @@ public async Task RemoveMemberAsync(string groupObjectId, string membe case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -193,7 +193,7 @@ public Response RemoveMember(string groupObjectId, string memberObjectId, Cancel case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -242,7 +242,7 @@ public async Task AddMemberAsync(string groupObjectId, GroupAddMemberP case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -269,7 +269,7 @@ public Response AddMember(string groupObjectId, GroupAddMemberParameters paramet case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -316,7 +316,7 @@ public async Task> CreateAsync(GroupCreateParameters parameter return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -343,7 +343,7 @@ public Response Create(GroupCreateParameters parameters, CancellationTo return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -384,7 +384,7 @@ public async Task> ListAsync(string filter = null, Can return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -405,7 +405,7 @@ public Response List(string filter = null, CancellationToken ca return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -450,7 +450,7 @@ public async Task> GetGroupMembersAsync(stri return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -477,7 +477,7 @@ public Response GetGroupMembers(string objectId, Canc return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -521,7 +521,7 @@ public async Task> GetAsync(string objectId, CancellationToken return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -548,7 +548,7 @@ public Response Get(string objectId, CancellationToken cancellationToke return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -587,7 +587,7 @@ public async Task DeleteAsync(string objectId, CancellationToken cance case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -609,7 +609,7 @@ public Response Delete(string objectId, CancellationToken cancellationToken = de case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -663,7 +663,7 @@ public async Task> GetMemberGroupsAsync(str return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -695,7 +695,7 @@ public Response GetMemberGroups(string objectId, Gro return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -740,7 +740,7 @@ public async Task> ListOwnersAsync(string ob return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -767,7 +767,7 @@ public Response ListOwners(string objectId, Cancellat return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -816,7 +816,7 @@ public async Task AddOwnerAsync(string objectId, AddOwnerParameters pa case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -843,7 +843,7 @@ public Response AddOwner(string objectId, AddOwnerParameters parameters, Cancell case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -889,7 +889,7 @@ public async Task RemoveOwnerAsync(string objectId, string ownerObject case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -916,7 +916,7 @@ public Response RemoveOwner(string objectId, string ownerObjectId, CancellationT case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -960,7 +960,7 @@ public async Task> ListNextAsync(string nextLink, Canc return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -987,7 +987,7 @@ public Response ListNext(string nextLink, CancellationToken can return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1031,7 +1031,7 @@ public async Task> GetGroupMembersNextAsync( return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1058,7 +1058,7 @@ public Response GetGroupMembersNext(string nextLink, return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1103,7 +1103,7 @@ public async Task> ListOwnersNextPageAsync(s return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1135,7 +1135,7 @@ public Response ListOwnersNextPage(string nextLink, s return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1175,7 +1175,7 @@ public async Task> ListNextNextPageAsync(string nextLi return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1202,7 +1202,7 @@ public Response ListNextNextPage(string nextLink, CancellationT return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1242,7 +1242,7 @@ public async Task> GetGroupMembersNextNextPa return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1269,7 +1269,7 @@ public Response GetGroupMembersNextNextPage(string ne return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/OAuth2PermissionGrantRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/OAuth2PermissionGrantRestOperations.cs index 123247cacc411..6ad72bacc6d6d 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/OAuth2PermissionGrantRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/OAuth2PermissionGrantRestOperations.cs @@ -87,7 +87,7 @@ public async Task> ListAsync(string fi return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -108,7 +108,7 @@ public Response List(string filter = null, Canc return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -152,7 +152,7 @@ public async Task> CreateAsync(OAuth2PermissionG return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -173,7 +173,7 @@ public Response Create(OAuth2PermissionGrant body = null, return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -212,7 +212,7 @@ public async Task DeleteAsync(string objectId, CancellationToken cance case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -234,7 +234,7 @@ public Response Delete(string objectId, CancellationToken cancellationToken = de case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -278,7 +278,7 @@ public async Task> ListNextAsync(strin return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -305,7 +305,7 @@ public Response ListNext(string nextLink, Cance return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -345,7 +345,7 @@ public async Task> ListNextNextPageAsy return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -372,7 +372,7 @@ public Response ListNextNextPage(string nextLin return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ObjectsRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ObjectsRestOperations.cs index bb5d371ca452a..793df989097a1 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ObjectsRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ObjectsRestOperations.cs @@ -93,7 +93,7 @@ public async Task> GetObjectsByObjectIdsAsyn return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -120,7 +120,7 @@ public Response GetObjectsByObjectIds(GetObjectsParam return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -164,7 +164,7 @@ public async Task> GetObjectsByObjectIdsNext return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -191,7 +191,7 @@ public Response GetObjectsByObjectIdsNext(string next return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -231,7 +231,7 @@ public async Task> GetObjectsByObjectIdsNext return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -258,7 +258,7 @@ public Response GetObjectsByObjectIdsNextNextPage(str return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ServicePrincipalsRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ServicePrincipalsRestOperations.cs index 0972c1eb1da8c..808eb30b705c2 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ServicePrincipalsRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/ServicePrincipalsRestOperations.cs @@ -93,7 +93,7 @@ public async Task> CreateAsync(ServicePrincipalCreate return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -120,7 +120,7 @@ public Response Create(ServicePrincipalCreateParameters parame return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -161,7 +161,7 @@ public async Task> ListAsync(string filter return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -182,7 +182,7 @@ public Response List(string filter = null, Cancellat return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -230,7 +230,7 @@ public async Task UpdateAsync(string objectId, ServicePrincipalUpdateP case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -257,7 +257,7 @@ public Response Update(string objectId, ServicePrincipalUpdateParameters paramet case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -296,7 +296,7 @@ public async Task DeleteAsync(string objectId, CancellationToken cance case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -318,7 +318,7 @@ public Response Delete(string objectId, CancellationToken cancellationToken = de case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -362,7 +362,7 @@ public async Task> GetAsync(string objectId, Cancella return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -389,7 +389,7 @@ public Response Get(string objectId, CancellationToken cancell return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -434,7 +434,7 @@ public async Task> ListAppRoleAssignedToAs return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -461,7 +461,7 @@ public Response ListAppRoleAssignedTo(string object return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -506,7 +506,7 @@ public async Task> ListAppRoleAssignmentsA return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -533,7 +533,7 @@ public Response ListAppRoleAssignments(string objec return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -578,7 +578,7 @@ public async Task> ListOwnersAsync(string ob return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -605,7 +605,7 @@ public Response ListOwners(string objectId, Cancellat return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -654,7 +654,7 @@ public async Task AddOwnerAsync(string objectId, AddOwnerParameters pa case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -681,7 +681,7 @@ public Response AddOwner(string objectId, AddOwnerParameters parameters, Cancell case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -727,7 +727,7 @@ public async Task RemoveOwnerAsync(string objectId, string ownerObject case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -754,7 +754,7 @@ public Response RemoveOwner(string objectId, string ownerObjectId, CancellationT case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -799,7 +799,7 @@ public async Task> ListKeyCredentialsAsync(str return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -826,7 +826,7 @@ public Response ListKeyCredentials(string objectId, Can return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -875,7 +875,7 @@ public async Task UpdateKeyCredentialsAsync(string objectId, KeyCreden case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -902,7 +902,7 @@ public Response UpdateKeyCredentials(string objectId, KeyCredentialsUpdateParame case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -947,7 +947,7 @@ public async Task> ListPasswordCredential return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -974,7 +974,7 @@ public Response ListPasswordCredentials(string obj return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1023,7 +1023,7 @@ public async Task UpdatePasswordCredentialsAsync(string objectId, Pass case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1050,7 +1050,7 @@ public Response UpdatePasswordCredentials(string objectId, PasswordCredentialsUp case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1094,7 +1094,7 @@ public async Task> ListNextAsync(string nex return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1121,7 +1121,7 @@ public Response ListNext(string nextLink, Cancellati return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1166,7 +1166,7 @@ public async Task> ListAppRoleAssignedToNe return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1198,7 +1198,7 @@ public Response ListAppRoleAssignedToNextPage(strin return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1243,7 +1243,7 @@ public async Task> ListAppRoleAssignmentsN return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1275,7 +1275,7 @@ public Response ListAppRoleAssignmentsNextPage(stri return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1320,7 +1320,7 @@ public async Task> ListOwnersNextPageAsync(s return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1352,7 +1352,7 @@ public Response ListOwnersNextPage(string nextLink, s return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -1392,7 +1392,7 @@ public async Task> ListNextNextPageAsync(st return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -1419,7 +1419,7 @@ public Response ListNextNextPage(string nextLink, Ca return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/SignedInUserRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/SignedInUserRestOperations.cs index 49ce61ad29613..640e568837f32 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/SignedInUserRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/SignedInUserRestOperations.cs @@ -82,7 +82,7 @@ public async Task> GetAsync(CancellationToken cancellationToken = return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -102,7 +102,7 @@ public Response Get(CancellationToken cancellationToken = default) return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -138,7 +138,7 @@ public async Task> ListOwnedObjectsAsync(Can return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -158,7 +158,7 @@ public Response ListOwnedObjects(CancellationToken ca return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -202,7 +202,7 @@ public async Task> ListOwnedObjectsNextAsync return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -229,7 +229,7 @@ public Response ListOwnedObjectsNext(string nextLink, return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -269,7 +269,7 @@ public async Task> ListOwnedObjectsNextNextP return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -296,7 +296,7 @@ public Response ListOwnedObjectsNextNextPage(string n return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/UsersRestOperations.cs b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/UsersRestOperations.cs index aed12359a9839..a7eb338713395 100644 --- a/sdk/testcommon/Azure.Graph.Rbac/src/Generated/UsersRestOperations.cs +++ b/sdk/testcommon/Azure.Graph.Rbac/src/Generated/UsersRestOperations.cs @@ -93,7 +93,7 @@ public async Task> CreateAsync(UserCreateParameters parameters, C return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -120,7 +120,7 @@ public Response Create(UserCreateParameters parameters, CancellationToken return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -171,7 +171,7 @@ public async Task> ListAsync(string filter = null, stri return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -194,7 +194,7 @@ public Response List(string filter = null, string expand = null, return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -238,7 +238,7 @@ public async Task> GetAsync(string upnOrObjectId, CancellationTok return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -265,7 +265,7 @@ public Response Get(string upnOrObjectId, CancellationToken cancellationTo return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -313,7 +313,7 @@ public async Task UpdateAsync(string upnOrObjectId, UserUpdateParamete case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -340,7 +340,7 @@ public Response Update(string upnOrObjectId, UserUpdateParameters parameters, Ca case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -379,7 +379,7 @@ public async Task DeleteAsync(string upnOrObjectId, CancellationToken case 204: return message.Response; default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -401,7 +401,7 @@ public Response Delete(string upnOrObjectId, CancellationToken cancellationToken case 204: return message.Response; default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -455,7 +455,7 @@ public async Task> GetMemberGroupsAsync(stri return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -487,7 +487,7 @@ public Response GetMemberGroups(string objectId, User return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -531,7 +531,7 @@ public async Task> ListNextAsync(string nextLink, Cance return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -558,7 +558,7 @@ public Response ListNext(string nextLink, CancellationToken canc return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } @@ -598,7 +598,7 @@ public async Task> ListNextNextPageAsync(string nextLin return Response.FromValue(value, message.Response); } default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + throw new RequestFailedException(message.Response); } } @@ -625,7 +625,7 @@ public Response ListNextNextPage(string nextLink, CancellationTo return Response.FromValue(value, message.Response); } default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); + throw new RequestFailedException(message.Response); } } } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs index ca40365eabc88..1d7088bc5b87f 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs @@ -229,7 +229,7 @@ async ValueTask>> IOperation< } else if (update.Value.Status == DocumentTranslationStatus.ValidationFailed) { - RequestFailedException requestFailedException = _diagnostics.CreateRequestFailedException(rawResponse, update.Value.Error, CreateAdditionalInformation(update.Value.Error)); + RequestFailedException requestFailedException = new RequestFailedException(rawResponse); return OperationState>.Failure(rawResponse, requestFailedException); } @@ -470,12 +470,5 @@ private T ValidateOperationHasResponse(T value) return value; } - - private static IDictionary CreateAdditionalInformation(ResponseError error) - { - if (string.IsNullOrEmpty(error.ToString())) - return null; - return new Dictionary(1) { { "AdditionalInformation", error.ToString() } }; - } } } From 23fa88677a0e659dcb2152e951bfb95542ead1f9 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Mon, 1 May 2023 15:46:31 -0700 Subject: [PATCH 10/16] API --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 4 ++++ sdk/core/Azure.Core/api/Azure.Core.net5.0.cs | 4 ++++ sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 4 ++++ sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs | 4 ++++ sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs | 4 ++++ sdk/core/Azure.Core/src/RequestFailedException.cs | 2 -- 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 6cc7128c79e64..5c88d59c49c87 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -270,8 +270,12 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, System.Exception? innerException) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, string? errorCode, System.Exception? innerException) { } protected RequestFailedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public RequestFailedException(string message) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs index a2492cfca8f0b..967eb93bc81e3 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs @@ -270,8 +270,12 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, System.Exception? innerException) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, string? errorCode, System.Exception? innerException) { } protected RequestFailedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public RequestFailedException(string message) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index a2492cfca8f0b..967eb93bc81e3 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -270,8 +270,12 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, System.Exception? innerException) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, string? errorCode, System.Exception? innerException) { } protected RequestFailedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public RequestFailedException(string message) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs index 6cc7128c79e64..5c88d59c49c87 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs @@ -270,8 +270,12 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, System.Exception? innerException) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, string? errorCode, System.Exception? innerException) { } protected RequestFailedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public RequestFailedException(string message) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 6cc7128c79e64..5c88d59c49c87 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -270,8 +270,12 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, System.Exception? innerException) { } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message, string? errorCode, System.Exception? innerException) { } protected RequestFailedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public RequestFailedException(string message) { } diff --git a/sdk/core/Azure.Core/src/RequestFailedException.cs b/sdk/core/Azure.Core/src/RequestFailedException.cs index 986afe5ac16b7..e5449f066bc7b 100644 --- a/sdk/core/Azure.Core/src/RequestFailedException.cs +++ b/sdk/core/Azure.Core/src/RequestFailedException.cs @@ -39,7 +39,6 @@ public class RequestFailedException : Exception, ISerializable /// Initializes a new instance of the class with a specified error message. /// The message that describes the error. - [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(string message) : this(0, message) { } @@ -47,7 +46,6 @@ public RequestFailedException(string message) : this(0, message) /// Initializes a new instance of the class with a specified error message, HTTP status code and a reference to the inner exception that is the cause of this exception. /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. - [EditorBrowsable(EditorBrowsableState.Never)] public RequestFailedException(string message, Exception? innerException) : this(0, message, innerException) { } From 8e3ecd1be504eeb132e312b793d7344d0e30621b Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Mon, 1 May 2023 20:39:14 -0700 Subject: [PATCH 11/16] Fix SB --- .../NamespacePropertiesExtensions.cs | 6 ++-- .../QueuePropertiesExtensions.cs | 8 +++--- .../QueueRuntimePropertiesExtensions.cs | 10 +++---- .../ServiceBusAdministrationClient.cs | 28 +++++++++---------- .../SubscriptionPropertiesExtensions.cs | 8 +++--- ...SubscriptionRuntimePropertiesExtensions.cs | 2 +- .../TopicPropertiesExtensions.cs | 10 +++---- .../TopicRuntimePropertiesExtensions.cs | 8 +++--- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs index d47c8f9f08919..de4cd748d1a43 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/NamespacePropertiesExtensions.cs @@ -11,7 +11,7 @@ namespace Azure.Messaging.ServiceBus.Administration { internal class NamespacePropertiesExtensions { - public static async Task ParseResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task ParseResponseAsync(Response response) { try { @@ -21,7 +21,7 @@ public static async Task ParseResponseAsync(Response respon { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(xDoc, response); } } } @@ -36,7 +36,7 @@ public static async Task ParseResponseAsync(Response respon innerException: new RequestFailedException(response)); } - private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static NamespaceProperties ParseFromEntryElement(XElement xEntry, Response response) { var nsInfo = new NamespaceProperties(); diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs index 94f5559406d2d..f4c32942985f4 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs @@ -66,7 +66,7 @@ public static async Task ParseResponseAsync(Response response, { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(xDoc, response); } } } @@ -81,7 +81,7 @@ public static async Task ParseResponseAsync(Response response, innerException: new RequestFailedException(response)); } - private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static QueueProperties ParseFromEntryElement(XElement xEntry, Response response) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; @@ -193,7 +193,7 @@ private static async Task ParseFromEntryElementAsync(XElement x return properties; } - public static async Task> ParsePagedResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task> ParsePagedResponseAsync(Response response) { try { @@ -208,7 +208,7 @@ public static async Task> ParsePagedResponseAsync(Response var entryList = xDoc.Elements(XName.Get("entry", AdministrationClientConstants.AtomNamespace)); foreach (var entry in entryList) { - queueList.Add(await ParseFromEntryElementAsync(entry, response, diagnostics).ConfigureAwait(false)); + queueList.Add(ParseFromEntryElement(entry, response)); } return queueList; diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs index f5af8e7791057..2419ee0471df1 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueRuntimePropertiesExtensions.cs @@ -12,7 +12,7 @@ namespace Azure.Messaging.ServiceBus.Administration { internal static class QueueRuntimePropertiesExtensions { - public static async Task ParseResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task ParseResponseAsync(Response response) { try { @@ -22,7 +22,7 @@ public static async Task ParseResponseAsync(Response res { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(xDoc, response); } } } @@ -37,7 +37,7 @@ public static async Task ParseResponseAsync(Response res innerException: new RequestFailedException(response)); } - private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static QueueRuntimeProperties ParseFromEntryElement(XElement xEntry, Response response) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; var qRuntime = new QueueRuntimeProperties(name); @@ -101,7 +101,7 @@ private static async Task ParseFromEntryElementAsync(XEl return qRuntime; } - public static async Task> ParsePagedResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task> ParsePagedResponseAsync(Response response) { try { @@ -116,7 +116,7 @@ public static async Task> ParsePagedResponseAsync(R var entryList = xDoc.Elements(XName.Get("entry", AdministrationClientConstants.AtomNamespace)); foreach (var entry in entryList) { - queueList.Add(await ParseFromEntryElementAsync(entry, response, diagnostics).ConfigureAwait(false)); + queueList.Add(ParseFromEntryElement(entry, response)); } return queueList; diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs index dadcdd691a432..9174c363bd877 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs @@ -250,7 +250,7 @@ public virtual async Task> GetNamespacePropertiesA null, false, cancellationToken).ConfigureAwait(false); - NamespaceProperties properties = await NamespacePropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + NamespaceProperties properties = await NamespacePropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); return Response.FromValue(properties, response); } @@ -646,7 +646,7 @@ public virtual async Task> GetTopicAsync( try { Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).ConfigureAwait(false); - TopicProperties properties = await TopicPropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + TopicProperties properties = await TopicPropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); return Response.FromValue(properties, response); } @@ -715,7 +715,7 @@ public virtual async Task> GetSubscriptionAsync try { Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName), null, false, cancellationToken).ConfigureAwait(false); - SubscriptionProperties properties = await SubscriptionPropertiesExtensions.ParseResponseAsync(topicName, response, _clientDiagnostics).ConfigureAwait(false); + SubscriptionProperties properties = await SubscriptionPropertiesExtensions.ParseResponseAsync(topicName, response).ConfigureAwait(false); return Response.FromValue(properties, response); } @@ -861,7 +861,7 @@ public virtual async Task> GetQueueRuntimePrope try { Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, true, cancellationToken).ConfigureAwait(false); - QueueRuntimeProperties runtimeProperties = await QueueRuntimePropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + QueueRuntimeProperties runtimeProperties = await QueueRuntimePropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); return Response.FromValue(runtimeProperties, response); } @@ -927,7 +927,7 @@ public virtual async Task> GetTopicRuntimePrope try { Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, true, cancellationToken).ConfigureAwait(false); - TopicRuntimeProperties runtimeProperties = await TopicRuntimePropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + TopicRuntimeProperties runtimeProperties = await TopicRuntimePropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); return Response.FromValue(runtimeProperties, response); } @@ -1059,7 +1059,7 @@ public virtual AsyncPageable GetQueuesAsync(CancellationToken c return _httpRequestAndResponse.GetEntitiesPageAsync( QueuesPath, nextSkip, - async response => await QueuePropertiesExtensions.ParsePagedResponseAsync(response, _clientDiagnostics).ConfigureAwait(false), + async response => await QueuePropertiesExtensions.ParsePagedResponseAsync(response).ConfigureAwait(false), cancellationToken); } catch (Exception ex) @@ -1117,7 +1117,7 @@ public virtual AsyncPageable GetTopicsAsync(CancellationToken c return _httpRequestAndResponse.GetEntitiesPageAsync( TopicsPath, nextSkip, - async response => await TopicPropertiesExtensions.ParsePagedResponseAsync(response, _clientDiagnostics).ConfigureAwait(false), + async response => await TopicPropertiesExtensions.ParsePagedResponseAsync(response).ConfigureAwait(false), cancellationToken); } catch (Exception ex) @@ -1324,7 +1324,7 @@ public virtual AsyncPageable GetQueuesRuntimePropertiesA return _httpRequestAndResponse.GetEntitiesPageAsync( QueuesPath, nextSkip, - async response => await QueueRuntimePropertiesExtensions.ParsePagedResponseAsync(response, _clientDiagnostics).ConfigureAwait(false), + async response => await QueueRuntimePropertiesExtensions.ParsePagedResponseAsync(response).ConfigureAwait(false), cancellationToken); } catch (Exception ex) @@ -1739,7 +1739,7 @@ public virtual async Task> CreateTopicAsync( null, null, cancellationToken).ConfigureAwait(false); - TopicProperties description = await TopicPropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + TopicProperties description = await TopicPropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); return Response.FromValue(description, response); } @@ -1950,7 +1950,7 @@ public virtual async Task> CreateSubscriptionAs subscription.ForwardTo, subscription.ForwardDeadLetteredMessagesTo, cancellationToken).ConfigureAwait(false); - SubscriptionProperties description = await SubscriptionPropertiesExtensions.ParseResponseAsync(subscription.TopicName, response, _clientDiagnostics).ConfigureAwait(false); + SubscriptionProperties description = await SubscriptionPropertiesExtensions.ParseResponseAsync(subscription.TopicName, response).ConfigureAwait(false); return Response.FromValue(description, response); } @@ -2205,7 +2205,7 @@ public virtual async Task> UpdateTopicAsync( forwardTo: null, fwdDeadLetterTo: null, cancellationToken).ConfigureAwait(false); - TopicProperties description = await TopicPropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + TopicProperties description = await TopicPropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); return Response.FromValue(description, response); } @@ -2287,7 +2287,7 @@ public virtual async Task> UpdateSubscriptionAs subscription.ForwardTo, subscription.ForwardDeadLetteredMessagesTo, cancellationToken).ConfigureAwait(false); - SubscriptionProperties description = await SubscriptionPropertiesExtensions.ParseResponseAsync(subscription.TopicName, response, _clientDiagnostics).ConfigureAwait(false); + SubscriptionProperties description = await SubscriptionPropertiesExtensions.ParseResponseAsync(subscription.TopicName, response).ConfigureAwait(false); return Response.FromValue(description, response); } @@ -2512,7 +2512,7 @@ public virtual async Task> TopicExistsAsync( try { response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).ConfigureAwait(false); - TopicProperties description = await TopicPropertiesExtensions.ParseResponseAsync(response, _clientDiagnostics).ConfigureAwait(false); + TopicProperties description = await TopicPropertiesExtensions.ParseResponseAsync(response).ConfigureAwait(false); } catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound) { @@ -2585,7 +2585,7 @@ public virtual async Task> SubscriptionExistsAsync( try { response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName), null, false, cancellationToken).ConfigureAwait(false); - SubscriptionProperties description = await SubscriptionPropertiesExtensions.ParseResponseAsync(topicName, response, _clientDiagnostics).ConfigureAwait(false); + SubscriptionProperties description = await SubscriptionPropertiesExtensions.ParseResponseAsync(topicName, response).ConfigureAwait(false); } catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound) { diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs index 81b0b63942f33..32345c8847d29 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionPropertiesExtensions.cs @@ -38,7 +38,7 @@ public static string NormalizeForwardToAddress(string forwardTo, string baseAddr return forwardToUri.AbsoluteUri; } - public static async Task ParseResponseAsync(string topicName, Response response, ClientDiagnostics diagnostics) + public static async Task ParseResponseAsync(string topicName, Response response) { try { @@ -48,7 +48,7 @@ public static async Task ParseResponseAsync(string topic { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(topicName, xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(topicName, xDoc, response); } } } @@ -77,7 +77,7 @@ public static async Task> ParsePagedResponseAsync(s var entryList = xDoc.Elements(XName.Get("entry", AdministrationClientConstants.AtomNamespace)); foreach (var entry in entryList) { - subscriptionList.Add(await ParseFromEntryElementAsync(topicName, entry, response, diagnostics).ConfigureAwait(false)); + subscriptionList.Add(ParseFromEntryElement(topicName, entry, response)); } return subscriptionList; @@ -95,7 +95,7 @@ public static async Task> ParsePagedResponseAsync(s innerException: new RequestFailedException(response)); } - private static async Task ParseFromEntryElementAsync(string topicName, XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static SubscriptionProperties ParseFromEntryElement(string topicName, XElement xEntry, Response response) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; var subscriptionProperties = new SubscriptionProperties(topicName, name); diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs index a85ed15a1b6f1..bddf6e2af12fd 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/SubscriptionRuntimePropertiesExtensions.cs @@ -37,7 +37,7 @@ public static async Task ParseResponseAsync(strin innerException: new RequestFailedException(response)); } - private static void SubscriptionRuntimeProperties ParseFromEntryElement(string topicName, XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static SubscriptionRuntimeProperties ParseFromEntryElement(string topicName, XElement xEntry, Response response, ClientDiagnostics diagnostics) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; var subscriptionRuntimeInfo = new SubscriptionRuntimeProperties(topicName, name); diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs index 64e8b3a871a88..a8e344122877a 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs @@ -13,7 +13,7 @@ namespace Azure.Messaging.ServiceBus.Administration { internal static class TopicPropertiesExtensions { - public static async Task ParseResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task ParseResponseAsync(Response response) { try { @@ -23,7 +23,7 @@ public static async Task ParseResponseAsync(Response response, { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(xDoc, response); } } } @@ -38,7 +38,7 @@ public static async Task ParseResponseAsync(Response response, innerException: new RequestFailedException(response)); } - public static async Task> ParsePagedResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task> ParsePagedResponseAsync(Response response) { try { @@ -53,7 +53,7 @@ public static async Task> ParsePagedResponseAsync(Response var entryList = xDoc.Elements(XName.Get("entry", AdministrationClientConstants.AtomNamespace)); foreach (var entry in entryList) { - topicList.Add(await ParseFromEntryElementAsync(entry, response, diagnostics).ConfigureAwait(false)); + topicList.Add(ParseFromEntryElement(entry, response)); } return topicList; @@ -71,7 +71,7 @@ public static async Task> ParsePagedResponseAsync(Response innerException: new RequestFailedException(response)); } - private static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) + private static TopicProperties ParseFromEntryElement(XElement xEntry, Response response) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; var topicXml = xEntry.Element(XName.Get("content", AdministrationClientConstants.AtomNamespace))? diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs index a3fd5aa93209b..c592a4173834c 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicRuntimePropertiesExtensions.cs @@ -12,7 +12,7 @@ namespace Azure.Messaging.ServiceBus.Administration { internal static class TopicRuntimePropertiesExtensions { - public static async Task ParseResponseAsync(Response response, ClientDiagnostics diagnostics) + public static async Task ParseResponseAsync(Response response) { try { @@ -22,7 +22,7 @@ public static async Task ParseResponseAsync(Response res { if (xDoc.Name.LocalName == "entry") { - return await ParseFromEntryElementAsync(xDoc, response, diagnostics).ConfigureAwait(false); + return ParseFromEntryElement(xDoc, response); } } } @@ -37,7 +37,7 @@ public static async Task ParseResponseAsync(Response res innerException: new RequestFailedException(response)); } - public static async Task ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics) + public static TopicRuntimeProperties ParseFromEntryElement(XElement xEntry, Response response) { var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value; var topicRuntimeInfo = new TopicRuntimeProperties(name); @@ -105,7 +105,7 @@ public static async Task> ParsePagedResponseAsync(R var entryList = xDoc.Elements(XName.Get("entry", AdministrationClientConstants.AtomNamespace)); foreach (var entry in entryList) { - topicList.Add(await ParseFromEntryElementAsync(entry, response, diagnostics).ConfigureAwait(false)); + topicList.Add(ParseFromEntryElement(entry, response)); } return topicList; From afdcbb37698ba54bc65b8dc2146e8ba6509c0917 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Mon, 1 May 2023 20:44:03 -0700 Subject: [PATCH 12/16] Update doc translation to use new constructor --- .../Azure.AI.Translation.Document.sln | 6 ++++++ .../src/Azure.AI.Translation.Document.csproj | 3 +++ .../src/DocumentTranslationOperation.cs | 14 +++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sdk/translation/Azure.AI.Translation.Document/Azure.AI.Translation.Document.sln b/sdk/translation/Azure.AI.Translation.Document/Azure.AI.Translation.Document.sln index 50943daadd13c..58e98638c112f 100644 --- a/sdk/translation/Azure.AI.Translation.Document/Azure.AI.Translation.Document.sln +++ b/sdk/translation/Azure.AI.Translation.Document/Azure.AI.Translation.Document.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.Translation.Document.Tests", "tests\Azure.AI.Translation.Document.Tests.csproj", "{764BFCBB-D8FD-401A-8075-B8F5F10B4991}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core", "..\..\core\Azure.Core\src\Azure.Core.csproj", "{DF34BB8D-DF45-43BE-84AC-9E1BC6AA212A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +33,10 @@ Global {D55A8124-3081-4F60-A2D7-744819FA0295}.Debug|Any CPU.Build.0 = Debug|Any CPU {D55A8124-3081-4F60-A2D7-744819FA0295}.Release|Any CPU.ActiveCfg = Release|Any CPU {D55A8124-3081-4F60-A2D7-744819FA0295}.Release|Any CPU.Build.0 = Release|Any CPU + {DF34BB8D-DF45-43BE-84AC-9E1BC6AA212A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF34BB8D-DF45-43BE-84AC-9E1BC6AA212A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF34BB8D-DF45-43BE-84AC-9E1BC6AA212A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF34BB8D-DF45-43BE-84AC-9E1BC6AA212A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Azure.AI.Translation.Document.csproj b/sdk/translation/Azure.AI.Translation.Document/src/Azure.AI.Translation.Document.csproj index 949b6adff5399..f996d35d51480 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Azure.AI.Translation.Document.csproj +++ b/sdk/translation/Azure.AI.Translation.Document/src/Azure.AI.Translation.Document.csproj @@ -13,6 +13,9 @@ + + + diff --git a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs index 1d7088bc5b87f..70bb6a8074966 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs @@ -229,7 +229,12 @@ async ValueTask>> IOperation< } else if (update.Value.Status == DocumentTranslationStatus.ValidationFailed) { - RequestFailedException requestFailedException = new RequestFailedException(rawResponse); + RequestFailedException requestFailedException = new RequestFailedException( + rawResponse, + null, + update.Value.Error, + CreateAdditionalInformation(update.Value.Error)); + return OperationState>.Failure(rawResponse, requestFailedException); } @@ -470,5 +475,12 @@ private T ValidateOperationHasResponse(T value) return value; } + + private static IDictionary CreateAdditionalInformation(ResponseError error) + { + if (string.IsNullOrEmpty(error.ToString())) + return null; + return new Dictionary(1) { { "AdditionalInformation", error.ToString() } }; + } } } From 2bd9294e84d796661d49fc9f319ba5ede00800a4 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Mon, 1 May 2023 21:17:35 -0700 Subject: [PATCH 13/16] Fix tests --- .../Administration/HttpRequestAndResponse.cs | 4 +- .../Administration/RequestResponseTests.cs | 40 +++++++++---------- .../SubscriptionPropertiesTests.cs | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs index 34bf2f6273800..5612218832c1f 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs @@ -41,7 +41,7 @@ public HttpRequestAndResponse( _port = GetPort(_fullyQualifiedNamespace); } - internal void ThrowIfRequestFailedAsync(Request request, Response response) + internal void ThrowIfRequestFailed(Request request, Response response) { if ((response.Status >= 200) && (response.Status < 400)) { @@ -274,7 +274,7 @@ private async Task SendHttpRequestAsync( Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - ThrowIfRequestFailedAsync(request, response); + ThrowIfRequestFailed(request, response); return response; } diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs index 9b25a1e49a3be..0cf66da4f1fc2 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs @@ -24,12 +24,12 @@ public RequestResponseTests() } [Test] - public async Task ThrowsUnauthorizedOn401() + public void ThrowsUnauthorizedOn401() { try { MockResponse response = new MockResponse((int)HttpStatusCode.Unauthorized); - await _requestResponse.ThrowIfRequestFailedAsync(new MockRequest(), response); + _requestResponse.ThrowIfRequestFailed(new MockRequest(), response); } catch (UnauthorizedAccessException ex) { @@ -41,12 +41,12 @@ public async Task ThrowsUnauthorizedOn401() } [Test] - public async Task ThrowsMessagingEntityNotFoundOn404() + public void ThrowsMessagingEntityNotFoundOn404() { try { MockResponse response = new MockResponse((int)HttpStatusCode.NotFound); - await _requestResponse.ThrowIfRequestFailedAsync(new MockRequest(), response); + _requestResponse.ThrowIfRequestFailed(new MockRequest(), response); } catch (ServiceBusException ex) { @@ -59,12 +59,12 @@ public async Task ThrowsMessagingEntityNotFoundOn404() } [Test] - public async Task ThrowsMessagingEntityAlreadyExistsOnCreateConflict() + public void ThrowsMessagingEntityAlreadyExistsOnCreateConflict() { try { MockResponse response = new MockResponse((int)HttpStatusCode.Conflict); - await _requestResponse.ThrowIfRequestFailedAsync(new MockRequest() { Method = RequestMethod.Put }, response); + _requestResponse.ThrowIfRequestFailed(new MockRequest() { Method = RequestMethod.Put }, response); } catch (ServiceBusException ex) { @@ -78,14 +78,14 @@ public async Task ThrowsMessagingEntityAlreadyExistsOnCreateConflict() } [Test] - public async Task ThrowsGeneralErrorOnUpdateConflict() + public void ThrowsGeneralErrorOnUpdateConflict() { try { MockResponse response = new MockResponse((int)HttpStatusCode.Conflict); var request = new MockRequest() { Method = RequestMethod.Put }; request.Headers.Add("If-Match", "*"); - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (ServiceBusException ex) { @@ -99,13 +99,13 @@ public async Task ThrowsGeneralErrorOnUpdateConflict() } [Test] - public async Task ThrowsGeneralErrorOnDeleteConflict() + public void ThrowsGeneralErrorOnDeleteConflict() { try { MockResponse response = new MockResponse((int)HttpStatusCode.Conflict); var request = new MockRequest() { Method = RequestMethod.Delete }; - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (ServiceBusException ex) { @@ -119,13 +119,13 @@ public async Task ThrowsGeneralErrorOnDeleteConflict() } [Test] - public async Task ThrowsServiceBusyOnServiceUnavailable() + public void ThrowsServiceBusyOnServiceUnavailable() { try { MockResponse response = new MockResponse((int)HttpStatusCode.ServiceUnavailable); var request = new MockRequest() { Method = RequestMethod.Delete }; - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (ServiceBusException ex) { @@ -139,13 +139,13 @@ public async Task ThrowsServiceBusyOnServiceUnavailable() } [Test] - public async Task ThrowsArgumentExceptionOnBadRequest() + public void ThrowsArgumentExceptionOnBadRequest() { try { MockResponse response = new MockResponse((int)HttpStatusCode.BadRequest); var request = new MockRequest() { Method = RequestMethod.Put }; - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (ArgumentException ex) { @@ -157,7 +157,7 @@ public async Task ThrowsArgumentExceptionOnBadRequest() } [Test] - public async Task ThrowsInvalidOperationOnForbiddenSubcode() + public void ThrowsInvalidOperationOnForbiddenSubcode() { try { @@ -165,7 +165,7 @@ public async Task ThrowsInvalidOperationOnForbiddenSubcode() (int)HttpStatusCode.Forbidden, AdministrationClientConstants.ForbiddenInvalidOperationSubCode); var request = new MockRequest() { Method = RequestMethod.Put }; - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (InvalidOperationException ex) { @@ -177,14 +177,14 @@ public async Task ThrowsInvalidOperationOnForbiddenSubcode() } [Test] - public async Task ThrowsQuotaExceededOnForbiddenStatus() + public void ThrowsQuotaExceededOnForbiddenStatus() { try { MockResponse response = new MockResponse( (int)HttpStatusCode.Forbidden); var request = new MockRequest() { Method = RequestMethod.Delete }; - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (ServiceBusException ex) { @@ -198,14 +198,14 @@ public async Task ThrowsQuotaExceededOnForbiddenStatus() } [Test] - public async Task ThrowsGeneralFailureOnOtherError() + public void ThrowsGeneralFailureOnOtherError() { try { MockResponse response = new MockResponse( 429); var request = new MockRequest() { Method = RequestMethod.Put }; - await _requestResponse.ThrowIfRequestFailedAsync(request, response); + _requestResponse.ThrowIfRequestFailed(request, response); } catch (ServiceBusException ex) { diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/SubscriptionPropertiesTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/SubscriptionPropertiesTests.cs index e10ddab9f76d7..544e9a6873d71 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/SubscriptionPropertiesTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/SubscriptionPropertiesTests.cs @@ -177,7 +177,7 @@ public async Task UnknownElementsInAtomXmlHandledCorrectly() $""; MockResponse response = new MockResponse(200); response.SetContent(subscriptionDescriptionXml); - SubscriptionProperties subscriptionDesc = await SubscriptionPropertiesExtensions.ParseResponseAsync("abcd", response, new ClientDiagnostics(new ServiceBusAdministrationClientOptions())); + SubscriptionProperties subscriptionDesc = await SubscriptionPropertiesExtensions.ParseResponseAsync("abcd", response); Assert.NotNull(subscriptionDesc.UnknownProperties); XDocument doc = SubscriptionPropertiesExtensions.Serialize(subscriptionDesc); From f0006f94f225325f293cba43bdc2dcb0ec5d7ad9 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 2 May 2023 23:34:29 -0700 Subject: [PATCH 14/16] Use RequestFailedDetailsParser --- .../Azure.Data.AppConfiguration.sln | 6 ++++ .../src/ConfigurationClient.cs | 34 +++++++++++++++---- .../src/PostLedgerEntryOperation.cs | 20 +++++++++-- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net5.0.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 2 +- .../api/Azure.Core.netcoreapp2.1.cs | 2 +- .../api/Azure.Core.netstandard2.0.cs | 2 +- .../Azure.Core/src/RequestFailedException.cs | 22 +++++------- .../src/Internal/ClientCommon.cs | 23 +++++++++++-- .../src/ImdsManagedIdentitySource.cs | 20 ++++++++++- .../src/BatchErrors.cs | 12 ++++++- .../src/DocumentTranslationOperation.cs | 21 ++++++++++-- 13 files changed, 136 insertions(+), 32 deletions(-) diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/Azure.Data.AppConfiguration.sln b/sdk/appconfiguration/Azure.Data.AppConfiguration/Azure.Data.AppConfiguration.sln index 703e047f7a860..f52d6bf74a8b0 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/Azure.Data.AppConfiguration.sln +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/Azure.Data.AppConfiguration.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.AppConfiguration EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{676CF11A-2788-478F-ABBA-0CD79CF60BE3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core", "..\..\core\Azure.Core\src\Azure.Core.csproj", "{859DE6FF-6030-4388-8FE6-1B9C471DD7B8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,10 @@ Global {676CF11A-2788-478F-ABBA-0CD79CF60BE3}.Debug|Any CPU.Build.0 = Debug|Any CPU {676CF11A-2788-478F-ABBA-0CD79CF60BE3}.Release|Any CPU.ActiveCfg = Release|Any CPU {676CF11A-2788-478F-ABBA-0CD79CF60BE3}.Release|Any CPU.Build.0 = Release|Any CPU + {859DE6FF-6030-4388-8FE6-1B9C471DD7B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {859DE6FF-6030-4388-8FE6-1B9C471DD7B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {859DE6FF-6030-4388-8FE6-1B9C471DD7B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {859DE6FF-6030-4388-8FE6-1B9C471DD7B8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs index e8380a25d6142..4abdec7b0d373 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs @@ -175,7 +175,7 @@ public virtual async Task> AddConfigurationSettin case 201: return await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false); case 412: - throw new RequestFailedException(response, null, new ResponseError(null, "Setting was already present.")); + throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()); default: throw new RequestFailedException(response); } @@ -214,7 +214,7 @@ public virtual Response AddConfigurationSetting(Configurat case 201: return CreateResponse(response); case 412: - throw new RequestFailedException(response, null, new ResponseError(null, "Setting was already present.")); + throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()); default: throw new RequestFailedException(response); } @@ -283,7 +283,7 @@ public virtual async Task> SetConfigurationSettin return response.Status switch { 200 => await CreateResponseAsync(response, cancellationToken).ConfigureAwait(false), - 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only")), + 409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()), // Throws on 412 if resource was modified. _ => throw new RequestFailedException(response), @@ -326,7 +326,7 @@ public virtual Response SetConfigurationSetting(Configurat return response.Status switch { 200 => CreateResponse(response), - 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only")), + 409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()), // Throws on 412 if resource was modified. _ => throw new RequestFailedException(response), @@ -415,7 +415,7 @@ private async Task DeleteConfigurationSettingAsync(string key, string { 200 => response, 204 => response, - 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only")), + 409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()), // Throws on 412 if resource was modified. _ => throw new RequestFailedException(response) @@ -444,7 +444,7 @@ private Response DeleteConfigurationSetting(string key, string label, MatchCondi { 200 => response, 204 => response, - 409 => throw new RequestFailedException(response, null, new ResponseError(null, "The setting is read only.")), + 409 => throw new RequestFailedException(response, null, new ConfigurationRequestFailedDetailsParser()), // Throws on 412 if resource was modified. _ => throw new RequestFailedException(response) @@ -1618,5 +1618,27 @@ internal virtual Pageable GetSnapshots(string name, string after, IE HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSnapshotsNextPageRequest(nextLink, name, after, select, status, context); return PageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "ConfigurationClient.GetSnapshots", "items", "@nextLink", context); } + + private class ConfigurationRequestFailedDetailsParser : RequestFailedDetailsParser + { + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + switch (response.Status) + { + case 409: + error = new ResponseError(null, "The setting is read only"); + data = null; + return true; + case 412: + error = new ResponseError(null, "Setting was already present."); + data = null; + return true; + default: + error = null; + data = null; + return false; + } + } + } } } diff --git a/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs b/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs index 75d0381ee8778..372caaefec5ee 100644 --- a/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs +++ b/sdk/confidentialledger/Azure.Security.ConfidentialLedger/src/PostLedgerEntryOperation.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Net; using System.Text.Json; using System.Threading; @@ -63,8 +64,7 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella if (statusResponse.Status != (int)HttpStatusCode.OK) { - var error = new ResponseError(null, exceptionMessage); - var ex = new RequestFailedException(statusResponse, null, error); + var ex = new RequestFailedException(statusResponse, null, new PostLedgerEntryRequestFailedDetailsParser(exceptionMessage)); return OperationState.Failure(statusResponse, new RequestFailedException(exceptionMessage, ex)); } @@ -86,5 +86,21 @@ async ValueTask IOperation.UpdateStateAsync(bool async, Cancella /// public override bool HasCompleted => _operationInternal.HasCompleted; + + private class PostLedgerEntryRequestFailedDetailsParser : RequestFailedDetailsParser + { + private readonly string _message; + + public PostLedgerEntryRequestFailedDetailsParser(string message) + { + _message = message; + } + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + error = new ResponseError(null, _message); + data = null; + return true; + } + } } } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 5c88d59c49c87..2494ad4a9ba19 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -270,7 +270,7 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } - public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.Core.RequestFailedDetailsParser? detailsParser) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs index 967eb93bc81e3..e8504dc9b9653 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs @@ -270,7 +270,7 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } - public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.Core.RequestFailedDetailsParser? detailsParser) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index 967eb93bc81e3..e8504dc9b9653 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -270,7 +270,7 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } - public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.Core.RequestFailedDetailsParser? detailsParser) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs index 5c88d59c49c87..2494ad4a9ba19 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs @@ -270,7 +270,7 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } - public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.Core.RequestFailedDetailsParser? detailsParser) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 5c88d59c49c87..2494ad4a9ba19 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -270,7 +270,7 @@ public partial class RequestFailedException : System.Exception, System.Runtime.S { public RequestFailedException(Azure.Response response) { } public RequestFailedException(Azure.Response response, System.Exception? innerException) { } - public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.ResponseError? error, System.Collections.Generic.IDictionary? additionalInfo = null) { } + public RequestFailedException(Azure.Response response, System.Exception? innerException, Azure.Core.RequestFailedDetailsParser? detailsParser) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public RequestFailedException(int status, string message) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/core/Azure.Core/src/RequestFailedException.cs b/sdk/core/Azure.Core/src/RequestFailedException.cs index e5449f066bc7b..1eee32f33f366 100644 --- a/sdk/core/Azure.Core/src/RequestFailedException.cs +++ b/sdk/core/Azure.Core/src/RequestFailedException.cs @@ -120,10 +120,9 @@ public RequestFailedException(Response response, Exception? innerException) /// with an error message, HTTP status code, error code obtained from the specified response. /// The response to obtain error details from. /// An inner exception to associate with the new . - /// The error information to use when constructing the exception message. If null, this will be parsed from the Response body. - /// Additional information to include in the exception message. This will also be stored in the property. - public RequestFailedException(Response response, Exception? innerException, ResponseError? error, IDictionary? additionalInfo = null) - : this(response.Status, GetRequestFailedExceptionContent(response, error, additionalInfo), innerException) + /// The parser to use to parse the response content. + public RequestFailedException(Response response, Exception? innerException, RequestFailedDetailsParser? detailsParser) + : this(response.Status, GetRequestFailedExceptionContent(response, detailsParser), innerException) { _response = response; } @@ -152,19 +151,16 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont /// public Response? GetRawResponse() => _response; - internal static (string FormattedError, string? ErrorCode, IDictionary? Data) GetRequestFailedExceptionContent(Response response, ResponseError? error, IDictionary? additionalInfo) + internal static (string FormattedError, string? ErrorCode, IDictionary? Data) GetRequestFailedExceptionContent(Response response, RequestFailedDetailsParser? parser) { BufferResponseIfNeeded(response); + parser ??= response.RequestFailedDetailsParser; - // only attempt to parse the error and additional info if not already provided. - if (error == null && additionalInfo == null) + bool parseSuccess = parser == null ? TryExtractErrorContent(response, out ResponseError? error, out IDictionary? additionalInfo) : parser.TryParse(response, out error, out additionalInfo); + if (!parseSuccess) { - bool parseSuccess = response.RequestFailedDetailsParser == null ? TryExtractErrorContent(response, out error, out additionalInfo) : response.RequestFailedDetailsParser.TryParse(response, out error, out additionalInfo); - if (!parseSuccess) - { - error = null; - additionalInfo = null; - } + error = null; + additionalInfo = null; } StringBuilder messageBuilder = new(); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs index e5eefbca3649c..39c1767a7e998 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Internal/ClientCommon.cs @@ -68,13 +68,13 @@ public static RequestFailedException CreateExceptionForFailedOperation(Response } var responseError = new ResponseError(errorCode, errorMessage); - return new RequestFailedException(response, null, responseError, errorInfo); + return new RequestFailedException(response, null, new FormRecognizerRequestFailedDetailsParser(responseError, errorInfo)); } public static RequestFailedException CreateExceptionForFailedOperation(Response response, ResponseError error) { var additionalInfo = new Dictionary(1) { { "AdditionInformation", error.ToString() } }; - return new RequestFailedException(response, null, error, additionalInfo); + return new RequestFailedException(response, null, new FormRecognizerRequestFailedDetailsParser(error, additionalInfo)); } public static RecognizedFormCollection ConvertPrebuiltOutputToRecognizedForms(V2AnalyzeResult analyzeResult) @@ -103,5 +103,24 @@ public static IReadOnlyList ConvertToListOfPointF(IReadOnlyList c return points; } + + private class FormRecognizerRequestFailedDetailsParser : RequestFailedDetailsParser + { + private readonly ResponseError _error; + private readonly IDictionary _additionalInfo; + + public FormRecognizerRequestFailedDetailsParser(ResponseError error, IDictionary additionalInfo) + { + _error = error; + _additionalInfo = additionalInfo; + } + + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + error = _error; + data = _additionalInfo; + return true; + } + } } } diff --git a/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs b/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs index 1291307c8b168..5ba1d1f6cbbda 100644 --- a/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs +++ b/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Sockets; @@ -120,7 +121,7 @@ protected override async ValueTask HandleResponseAsync(bool async, if (baseMessage != null) { - string message = new RequestFailedException(response, null, new ResponseError(null, baseMessage)).Message; + string message = new RequestFailedException(response, null, new ImdsRequestFailedDetailsParser(baseMessage)).Message; var errorContentMessage = await GetMessageFromResponse(response, async, cancellationToken).ConfigureAwait(false); @@ -134,5 +135,22 @@ protected override async ValueTask HandleResponseAsync(bool async, return await base.HandleResponseAsync(async, context, response, cancellationToken).ConfigureAwait(false); } + + private class ImdsRequestFailedDetailsParser : RequestFailedDetailsParser + { + private readonly string _baseMessage; + + public ImdsRequestFailedDetailsParser(string baseMessage) + { + _baseMessage = baseMessage; + } + + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + error = new ResponseError(null, _baseMessage); + data = null; + return true; + } + } } } diff --git a/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs b/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs index ea364946110c1..94a329c2c57a5 100644 --- a/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs +++ b/sdk/storage/Azure.Storage.Blobs.Batch/src/BatchErrors.cs @@ -48,6 +48,16 @@ public static InvalidOperationException InvalidHttpHeaderLine(string headerLine) new InvalidOperationException($"Expected an HTTP header line, not {headerLine}"); public static RequestFailedException InvalidResponse(ClientDiagnostics clientDiagnostics, Response response, Exception innerException) => - new RequestFailedException(response, innerException, new ResponseError(null, "Invalid response")); + new RequestFailedException(response, innerException, new BatchRequestFailedDetailsParser()); + + private class BatchRequestFailedDetailsParser : RequestFailedDetailsParser + { + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + error = new ResponseError(null, "Invalid response"); + data = null; + return true; + } + } } } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs index 70bb6a8074966..d27649aec2fd3 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs @@ -232,8 +232,7 @@ async ValueTask>> IOperation< RequestFailedException requestFailedException = new RequestFailedException( rawResponse, null, - update.Value.Error, - CreateAdditionalInformation(update.Value.Error)); + new DocumentTranslationOperationRequestFailedDetailsParser(update.Value.Error, CreateAdditionalInformation(update.Value.Error))); return OperationState>.Failure(rawResponse, requestFailedException); } @@ -482,5 +481,23 @@ private static IDictionary CreateAdditionalInformation(ResponseE return null; return new Dictionary(1) { { "AdditionalInformation", error.ToString() } }; } + + private class DocumentTranslationOperationRequestFailedDetailsParser : RequestFailedDetailsParser + { + private readonly ResponseError _error; + private readonly IDictionary _additionalInfo; + + public DocumentTranslationOperationRequestFailedDetailsParser(ResponseError error, IDictionary additionalInfo) + { + _error = error; + _additionalInfo = additionalInfo; + } + public override bool TryParse(Response response, out ResponseError error, out IDictionary data) + { + error = _error; + data = _additionalInfo; + return false; + } + } } } From 669396cb54880307ff6eb034e88f492df14be098 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 2 May 2023 23:40:54 -0700 Subject: [PATCH 15/16] Add and --- sdk/core/Azure.Core/src/RequestFailedException.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/core/Azure.Core/src/RequestFailedException.cs b/sdk/core/Azure.Core/src/RequestFailedException.cs index 1eee32f33f366..2bc1df8b90d95 100644 --- a/sdk/core/Azure.Core/src/RequestFailedException.cs +++ b/sdk/core/Azure.Core/src/RequestFailedException.cs @@ -100,7 +100,7 @@ internal RequestFailedException(int status, (string FormatMessage, string? Error } /// Initializes a new instance of the class - /// with an error message, HTTP status code, error code obtained from the specified response. + /// with an error message, HTTP status code, and error code obtained from the specified response. /// The response to obtain error details from. public RequestFailedException(Response response) : this(response, null) @@ -108,7 +108,7 @@ public RequestFailedException(Response response) } /// Initializes a new instance of the class - /// with an error message, HTTP status code, error code obtained from the specified response. + /// with an error message, HTTP status code, and error code obtained from the specified response. /// The response to obtain error details from. /// An inner exception to associate with the new . public RequestFailedException(Response response, Exception? innerException) @@ -117,7 +117,7 @@ public RequestFailedException(Response response, Exception? innerException) } /// Initializes a new instance of the class - /// with an error message, HTTP status code, error code obtained from the specified response. + /// with an error message, HTTP status code, and error code obtained from the specified response. /// The response to obtain error details from. /// An inner exception to associate with the new . /// The parser to use to parse the response content. From 076c000cec8b0b855a4582eda18968e0a56fd555 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Tue, 2 May 2023 23:55:34 -0700 Subject: [PATCH 16/16] fix --- .../src/DocumentTranslationOperation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs index d27649aec2fd3..336cac2644285 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/DocumentTranslationOperation.cs @@ -496,7 +496,7 @@ public override bool TryParse(Response response, out ResponseError error, out ID { error = _error; data = _additionalInfo; - return false; + return true; } } }