diff --git a/sdk/core/Azure.Core/src/Pipeline/HttpPipeline.cs b/sdk/core/Azure.Core/src/Pipeline/HttpPipeline.cs
index 9a69c025bd5c8..b28244d63f788 100644
--- a/sdk/core/Azure.Core/src/Pipeline/HttpPipeline.cs
+++ b/sdk/core/Azure.Core/src/Pipeline/HttpPipeline.cs
@@ -71,7 +71,7 @@ public ValueTask SendAsync(HttpMessage message, CancellationToken cancellationTo
message.CancellationToken = cancellationToken;
AddHttpMessageProperties(message);
var value = _pipeline.Span[0].ProcessAsync(message, _pipeline.Slice(1));
- message.Response.ResponseClassifier = ResponseClassifier;
+ message.Response.Message = message;
return value;
}
@@ -85,7 +85,7 @@ public void Send(HttpMessage message, CancellationToken cancellationToken)
message.CancellationToken = cancellationToken;
AddHttpMessageProperties(message);
_pipeline.Span[0].Process(message, _pipeline.Slice(1));
- message.Response.ResponseClassifier = ResponseClassifier;
+ message.Response.Message = message;
}
///
/// Invokes the pipeline asynchronously with the provided request.
diff --git a/sdk/core/Azure.Core/src/Response.cs b/sdk/core/Azure.Core/src/Response.cs
index 47d6e672e1c88..4f64ecb830b53 100644
--- a/sdk/core/Azure.Core/src/Response.cs
+++ b/sdk/core/Azure.Core/src/Response.cs
@@ -113,14 +113,22 @@ public virtual BinaryData Content
/// The enumerating in the response.
protected internal abstract IEnumerable EnumerateHeaders();
- internal ResponseClassifier? ResponseClassifier { get; set; }
+ internal HttpMessage? Message { get; set; }
+
+ ///
+ ///
+ ///
+ public bool IsError()
+ {
+ return this.Message!.ResponseClassifier.IsErrorResponse(this.Message);
+ }
///
/// Throw a RequestFailedException appropriate to the Response.
///
public void Throw()
{
- throw this.ResponseClassifier!.CreateRequestFailedException(this);
+ throw this.Message!.ResponseClassifier.CreateRequestFailedException(this);
//throw new RequestFailedException("");
}
@@ -129,7 +137,7 @@ public void Throw()
///
public async Task ThrowAsync()
{
- throw await this.ResponseClassifier!.CreateRequestFailedExceptionAsync(this).ConfigureAwait(false);
+ throw await this.Message!.ResponseClassifier.CreateRequestFailedExceptionAsync(this).ConfigureAwait(false);
//throw new RequestFailedException("");
}
diff --git a/sdk/synapse/Azure.Analytics.Synapse.AccessControl/src/Models/SynapseRoleAssignment.cs b/sdk/synapse/Azure.Analytics.Synapse.AccessControl/src/Models/SynapseRoleAssignment.cs
index 27ea9f870e175..155eed6ec8451 100644
--- a/sdk/synapse/Azure.Analytics.Synapse.AccessControl/src/Models/SynapseRoleAssignment.cs
+++ b/sdk/synapse/Azure.Analytics.Synapse.AccessControl/src/Models/SynapseRoleAssignment.cs
@@ -44,19 +44,19 @@ public static implicit operator RequestContent(SynapseRoleAssignment value) => R
public static implicit operator SynapseRoleAssignment(Response response)
{
- switch (response.Status)
+ if (!response.IsError())
{
- case 200:
- return DeserializeResponse(response);
- default:
+ return DeserializeResponse(response);
+ }
+ else
+ {
+ response.Throw(); // What to do about Async here? Can you put awaits in operators?
+ }
+ // we should never get here, since we throw in the else statement above.
#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
- throw new NotImplementedException();
+ throw new NotSupportedException();
#pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
-
- //response.Throw();
- //break;
- }
}
private static SynapseRoleAssignment DeserializeResponse(Response response)
diff --git a/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientLiveTests.cs b/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientLiveTests.cs
index f83422919ef61..abbc4a2a099c4 100644
--- a/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientLiveTests.cs
+++ b/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientLiveTests.cs
@@ -87,18 +87,29 @@ public async Task CreateRoleAssignment_ModelTypeParameterOverload()
SynapseRoleAssignment roleAssignment = new SynapseRoleAssignment(roleId, principalId, scope);
- SynapseRoleAssignment returnedRoleAssignment = await client.CreateRoleAssignmentAsync(roleAssignmentId, roleAssignment, new RequestOptions()
+ // Calling the LLC directly:
+ Response response = await client.CreateRoleAssignmentAsync(roleAssignmentId, roleAssignment,
+ new RequestOptions()
+ {
+ StatusOption = ResponseStatusOption.NoThrow
+ });
+
+ // This is the implicit cast -- it will throw if the response is an error
+ // according to the classifier
+ SynapseRoleAssignment returnedRoleAssignment = response;
+
+ // But since we suppressed the error, we might want to think
+ // about it the following way:
+ if (response.IsError())
{
- StatusOption = ResponseStatusOption.NoThrow
- });
-
- // TODO: Finish this test and figure out the rest.
-
- await using DisposableClientRole role = await DisposableClientRole.Create(client, TestEnvironment);
-
- Assert.NotNull(role.Assignment.Id);
- Assert.NotNull(role.Assignment.Properties.RoleDefinitionId);
- Assert.NotNull(role.Assignment.Properties.PrincipalId);
+ await response.ThrowAsync();
+ }
+ else
+ {
+ Assert.NotNull(returnedRoleAssignment.Id);
+ Assert.NotNull(returnedRoleAssignment.Properties.RoleDefinitionId);
+ Assert.NotNull(returnedRoleAssignment.Properties.PrincipalId);
+ }
}
[Test]