From a466d224e005fa6d3d4b6ffb8f7ec0f9cb4983a3 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Sun, 12 May 2024 21:26:23 -0500 Subject: [PATCH] Add IResponseClassifier internal interface for unit tests --- .../Infrastructure/ResponseClassifier.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ShopifySharp/Infrastructure/ResponseClassifier.cs b/ShopifySharp/Infrastructure/ResponseClassifier.cs index 381e0d083..5e344d2f4 100644 --- a/ShopifySharp/Infrastructure/ResponseClassifier.cs +++ b/ShopifySharp/Infrastructure/ResponseClassifier.cs @@ -2,6 +2,21 @@ namespace ShopifySharp.Infrastructure; +internal interface IResponseClassifier +{ + /// + /// Specifies if the request should be retried based on the response status code. + /// + bool IsRetriableStatusCode(HttpStatusCode statusCode); + + /// + /// Specifies if the request was not successful based on the exception thrown. + /// + /// The exception being checked. + /// The total number of retries that have been attempted for the request that caused this exception. + bool IsRetriableException(ShopifyException ex, int totalRetriesAttempted); +} + /// /// 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. @@ -19,12 +34,10 @@ namespace ShopifySharp.Infrastructure; /// https://github.com/Azure/azure-sdk-for-net/blob/68a0baaf8fecfb6dc6847acc3140f1a206d327db/sdk/core/Azure.Core/src/ResponseClassifier.cs /// 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 - /// - /// Specifies if the request should be retried based on the response status code. - /// public virtual bool IsRetriableStatusCode(HttpStatusCode statusCode) { switch ((int)statusCode) @@ -41,11 +54,6 @@ public virtual bool IsRetriableStatusCode(HttpStatusCode statusCode) } } - /// - /// Specifies if the request was not successful based on the exception thrown. - /// - /// The exception being checked. - /// The total number of retries that have been attempted for the request that caused this exception. public virtual bool IsRetriableException(ShopifyException ex, int totalRetriesAttempted) { if (ex is ShopifyRateLimitException { Reason: ShopifyRateLimitReason.BucketFull })