diff --git a/src/Dfe.ContentSupport.Web/Configuration/CsContentfulOptions.cs b/src/Dfe.ContentSupport.Web/Configuration/CsContentfulOptions.cs index 6cdc72d..6441cf0 100644 --- a/src/Dfe.ContentSupport.Web/Configuration/CsContentfulOptions.cs +++ b/src/Dfe.ContentSupport.Web/Configuration/CsContentfulOptions.cs @@ -5,4 +5,5 @@ namespace Dfe.ContentSupport.Web.Configuration; public class CsContentfulOptions : ContentfulOptions { public int IncludeDepth { get; set; } = 10; + public int RetryAttempts { get; set; } = 3; } \ No newline at end of file diff --git a/src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs b/src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs index 0ff6a75..32c446a 100644 --- a/src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs +++ b/src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs @@ -12,6 +12,22 @@ public async Task> Query(QueryBuilder queryBuilder CancellationToken cancellationToken = default) where T : class { queryBuilder = queryBuilder.Include(options.IncludeDepth); - return await GetEntries(queryBuilder, cancellationToken); + + for (int attempt = 1; attempt <= options.RetryAttempts; attempt++) + { + try + { + return await GetEntries(queryBuilder, cancellationToken); + } + catch (Exception) + { + if (attempt == options.RetryAttempts) + { + throw; + } + } + } + + return default!; } } \ No newline at end of file