Skip to content

Commit

Permalink
Return an empty list if groups are not supported in pricing tier (#687)
Browse files Browse the repository at this point in the history
Co-authored-by: James Woodbridge <[email protected]>
  • Loading branch information
james-woodbridge and James Woodbridge authored Oct 11, 2024
1 parent 167a8de commit 65ca90d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tools/code/common/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -149,10 +150,19 @@ await uri.ListNames(pipeline, cancellationToken)
.Delete(pipeline, cancellationToken),
cancellationToken);

public static IAsyncEnumerable<GroupName> ListNames(this GroupsUri uri, HttpPipeline pipeline, CancellationToken cancellationToken) =>
pipeline.ListJsonObjects(uri.ToUri(), cancellationToken)
public static IAsyncEnumerable<GroupName> ListNames(this GroupsUri 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, GroupDto Dto)> List(this GroupsUri groupsUri, HttpPipeline pipeline, CancellationToken cancellationToken) =>
groupsUri.ListNames(pipeline, cancellationToken)
Expand Down

0 comments on commit 65ca90d

Please sign in to comment.