Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Response.IsError #24122

Merged
merged 29 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3e7655d
intial set-up for llc tests
annelo-msft Sep 8, 2021
501c49d
don't generate the code
annelo-msft Sep 8, 2021
7142fb9
saving work in progress
annelo-msft Sep 13, 2021
5eb05ef
Merge remote-tracking branch 'upstream/main' into init-llc-tests
annelo-msft Sep 14, 2021
c62ec9b
remove edits to Core
annelo-msft Sep 16, 2021
ede089b
simplify tests
annelo-msft Sep 16, 2021
2d39075
implement LLC method with mock transport
annelo-msft Sep 16, 2021
bab3d6c
Add in basic model cast functionality, without new Core features
annelo-msft Sep 16, 2021
71181eb
intial approach
annelo-msft Sep 17, 2021
3692d46
Merge remote-tracking branch 'upstream/main' into core-set-classifier
annelo-msft Sep 17, 2021
d7108c9
use ReqOpts to get default classifier functionality and do ro.Apply()
annelo-msft Sep 17, 2021
b70c9d8
simplify RequestOptions API; experiment with generating classifiers d…
annelo-msft Sep 20, 2021
4636282
update statusoptions value names and add tests
annelo-msft Sep 20, 2021
d174492
handle null options
annelo-msft Sep 20, 2021
789cb62
Merge remote-tracking branch 'upstream/main' into core-set-classifier
annelo-msft Sep 20, 2021
a5487f6
update api listing
annelo-msft Sep 20, 2021
347b16c
add IsError to PipelineResponse
annelo-msft Sep 20, 2021
243a191
move logic to pipeline
annelo-msft Sep 20, 2021
9fcedc4
undo changes to experimental
annelo-msft Sep 20, 2021
749502d
update Core API listing and undo changes to experimental
annelo-msft Sep 20, 2021
38b0143
add tests
annelo-msft Sep 20, 2021
a780216
await pipeline call
annelo-msft Sep 21, 2021
de8442f
initial move changes to Experimental
annelo-msft Sep 21, 2021
4e3406e
api tweaks
annelo-msft Sep 21, 2021
fff3b0b
Add ClassfiedResponse wrapping Response with IsError
annelo-msft Sep 21, 2021
4478c82
update api listing
annelo-msft Sep 21, 2021
b9e2dca
api tweaks
annelo-msft Sep 21, 2021
466d558
pr fb
annelo-msft Sep 22, 2021
e2a98e8
Merge remote-tracking branch 'upstream/main' into core-response-iserror
annelo-msft Sep 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected Response() { }
public virtual System.BinaryData Content { get { throw null; } }
public abstract System.IO.Stream? ContentStream { get; set; }
public virtual Azure.Core.ResponseHeaders Headers { get { throw null; } }
public bool IsError { get { throw null; } protected set { } }
public abstract string ReasonPhrase { get; }
public abstract int Status { get; }
protected internal abstract bool ContainsHeader(string name);
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected Response() { }
public virtual System.BinaryData Content { get { throw null; } }
public abstract System.IO.Stream? ContentStream { get; set; }
public virtual Azure.Core.ResponseHeaders Headers { get { throw null; } }
public bool IsError { get { throw null; } protected set { } }
public abstract string ReasonPhrase { get; }
public abstract int Status { get; }
protected internal abstract bool ContainsHeader(string name);
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected Response() { }
public virtual System.BinaryData Content { get { throw null; } }
public abstract System.IO.Stream? ContentStream { get; set; }
public virtual Azure.Core.ResponseHeaders Headers { get { throw null; } }
public bool IsError { get { throw null; } protected set { } }
public abstract string ReasonPhrase { get; }
public abstract int Status { get; }
protected internal abstract bool ContainsHeader(string name);
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected Response() { }
public virtual System.BinaryData Content { get { throw null; } }
public abstract System.IO.Stream? ContentStream { get; set; }
public virtual Azure.Core.ResponseHeaders Headers { get { throw null; } }
public bool IsError { get { throw null; } protected set { } }
public abstract string ReasonPhrase { get; }
public abstract int Status { get; }
protected internal abstract bool ContainsHeader(string name);
Expand Down
5 changes: 4 additions & 1 deletion sdk/core/Azure.Core/src/Pipeline/HttpPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public ValueTask SendAsync(HttpMessage message, CancellationToken cancellationTo
{
message.CancellationToken = cancellationToken;
AddHttpMessageProperties(message);
return _pipeline.Span[0].ProcessAsync(message, _pipeline.Slice(1));
var value = _pipeline.Span[0].ProcessAsync(message, _pipeline.Slice(1));
message.Response.EvaluateError(message);
annelo-msft marked this conversation as resolved.
Show resolved Hide resolved
return value;
}

/// <summary>
Expand All @@ -83,6 +85,7 @@ public void Send(HttpMessage message, CancellationToken cancellationToken)
message.CancellationToken = cancellationToken;
AddHttpMessageProperties(message);
_pipeline.Span[0].Process(message, _pipeline.Slice(1));
message.Response.EvaluateError(message);
}
/// <summary>
/// Invokes the pipeline asynchronously with the provided request.
Expand Down
10 changes: 10 additions & 0 deletions sdk/core/Azure.Core/src/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public virtual BinaryData Content
/// <returns>The <see cref="IEnumerable{T}"/> enumerating <see cref="HttpHeader"/> in the response.</returns>
protected internal abstract IEnumerable<HttpHeader> EnumerateHeaders();

/// <summary>
/// Indicates whether this response is an error, according to the REST API.
/// </summary>
public bool IsError { get; protected set; }
annelo-msft marked this conversation as resolved.
Show resolved Hide resolved

internal void EvaluateError(HttpMessage message)
{
IsError = message.ResponseClassifier.IsErrorResponse(message);
}

/// <summary>
/// Creates a new instance of <see cref="Response{T}"/> with the provided value and HTTP response.
/// </summary>
Expand Down
48 changes: 48 additions & 0 deletions sdk/core/Azure.Core/tests/PipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,54 @@ public void TryGetPropertyIsCaseSensitive()
Assert.False(message.TryGetProperty("SomeName", out _));
}

[Test]
public async Task PipelineSetsResponseIsErrorTrue()
{
var mockTransport = new MockTransport(
new MockResponse(500));

var pipeline = new HttpPipeline(mockTransport);

Request request = pipeline.CreateRequest();
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri("https://contoso.a.io"));
Response response = await pipeline.SendRequestAsync(request, CancellationToken.None);

Assert.IsTrue(response.IsError);
}

[Test]
public async Task PipelineSetsResponseIsErrorFalse()
{
var mockTransport = new MockTransport(
new MockResponse(200));

var pipeline = new HttpPipeline(mockTransport);

Request request = pipeline.CreateRequest();
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri("https://contoso.a.io"));
Response response = await pipeline.SendRequestAsync(request, CancellationToken.None);

Assert.IsFalse(response.IsError);
}

[Test]
public async Task CustomClassifierSetsResponseIsError()
{
var mockTransport = new MockTransport(
new MockResponse(404));

var pipeline = new HttpPipeline(mockTransport, responseClassifier: new CustomResponseClassifier());

Request request = pipeline.CreateRequest();
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri("https://contoso.a.io"));
Response response = await pipeline.SendRequestAsync(request, CancellationToken.None);

Assert.IsFalse(response.IsError);
}

private class CustomResponseClassifier : ResponseClassifier
{
public override bool IsRetriableResponse(HttpMessage message)
Expand Down