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

Return an empty list if product groups are not supported #681

Merged
Merged
Changes from all commits
Commits
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
17 changes: 14 additions & 3 deletions tools/code/common/ProductGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -122,10 +124,19 @@ public sealed record ProductGroupDto

public static class ProductGroupModule
{
public static IAsyncEnumerable<GroupName> ListNames(this ProductGroupsUri uri, HttpPipeline pipeline, CancellationToken cancellationToken) =>
pipeline.ListJsonObjects(uri.ToUri(), cancellationToken)
public static IAsyncEnumerable<GroupName> ListNames(this ProductGroupsUri uri, HttpPipeline pipeline, CancellationToken cancellationToken)
{
var exceptionHandler = (HttpRequestException exception) =>
exception.StatusCode == HttpStatusCode.BadRequest
&& exception.Message.Contains("MethodNotAllowedInPricingTier", StringComparison.OrdinalIgnoreCase)
? AsyncEnumerable.Empty<GroupName>()
: throw exception;

return pipeline.ListJsonObjects(uri.ToUri(), cancellationToken)
.Select(jsonObject => jsonObject.GetStringProperty("name"))
.Select(GroupName.From);
.Select(GroupName.From)
.Catch(exceptionHandler);
}

public static IAsyncEnumerable<(GroupName Name, ProductGroupDto Dto)> List(this ProductGroupsUri productGroupsUri, HttpPipeline pipeline, CancellationToken cancellationToken) =>
productGroupsUri.ListNames(pipeline, cancellationToken)
Expand Down