Skip to content

Commit

Permalink
Add IResponseClassifier internal interface for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed May 14, 2024
1 parent 1731c5f commit a466d22
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ShopifySharp/Infrastructure/ResponseClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

namespace ShopifySharp.Infrastructure;

internal interface IResponseClassifier
{
/// <summary>
/// Specifies if the request should be retried based on the response status code.
/// </summary>
bool IsRetriableStatusCode(HttpStatusCode statusCode);

/// <summary>
/// Specifies if the request was not successful based on the exception thrown.
/// </summary>
/// <param name="ex">The exception being checked.</param>
/// <param name="totalRetriesAttempted">The total number of retries that have been attempted for the request that caused this exception.</param>
bool IsRetriableException(ShopifyException ex, int totalRetriesAttempted);
}

/// <summary>
/// A type that analyzes HTTP responses and exceptions and determines if they should be retried,
/// and/or analyzes responses and determines if they should be treated as error responses.
Expand All @@ -19,12 +34,10 @@ namespace ShopifySharp.Infrastructure;
/// https://github.com/Azure/azure-sdk-for-net/blob/68a0baaf8fecfb6dc6847acc3140f1a206d327db/sdk/core/Azure.Core/src/ResponseClassifier.cs
/// </remarks>
internal class ResponseClassifier(bool retryUnexpectedRateLimitResponse, int maximumNonRateLimitRetriesPerRequest = 3)
: IResponseClassifier
{
// TODO: once the API design is finalized, make this class public and available to everyone using ShopifySharp

/// <summary>
/// Specifies if the request should be retried based on the response status code.
/// </summary>
public virtual bool IsRetriableStatusCode(HttpStatusCode statusCode)
{
switch ((int)statusCode)
Expand All @@ -41,11 +54,6 @@ public virtual bool IsRetriableStatusCode(HttpStatusCode statusCode)
}
}

/// <summary>
/// Specifies if the request was not successful based on the exception thrown.
/// </summary>
/// <param name="ex">The exception being checked.</param>
/// <param name="totalRetriesAttempted">The total number of retries that have been attempted for the request that caused this exception.</param>
public virtual bool IsRetriableException(ShopifyException ex, int totalRetriesAttempted)
{
if (ex is ShopifyRateLimitException { Reason: ShopifyRateLimitReason.BucketFull })
Expand Down

0 comments on commit a466d22

Please sign in to comment.