From ae9ff8eb48876829cb6cc520664730baa19cb9b3 Mon Sep 17 00:00:00 2001 From: Alan Leung Date: Thu, 22 Aug 2024 16:30:30 -0600 Subject: [PATCH] Initial fix and regression tested (#2571) --- .../Document Manager/DocumentManagerClient.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/prime-dotnet-webapi/HttpClients/Document Manager/DocumentManagerClient.cs b/prime-dotnet-webapi/HttpClients/Document Manager/DocumentManagerClient.cs index c245a1fd8f..9c4537184d 100644 --- a/prime-dotnet-webapi/HttpClients/Document Manager/DocumentManagerClient.cs +++ b/prime-dotnet-webapi/HttpClients/Document Manager/DocumentManagerClient.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using Flurl; +using Microsoft.Extensions.Logging; using Prime.Extensions; using Prime.HttpClients.DocumentManagerApiDefinitions; @@ -13,11 +14,14 @@ namespace Prime.HttpClients public class DocumentManagerClient : IDocumentManagerClient { private readonly HttpClient _client; + private readonly ILogger _logger; - public DocumentManagerClient(HttpClient httpClient) + + public DocumentManagerClient(HttpClient httpClient, ILogger logger) { // Credentials and Base Url are set in Startup.cs _client = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + _logger = logger; } public async Task InitializeUploadAsync(string filename, string fileSize) @@ -59,7 +63,15 @@ public async Task SendFileAsync(Stream document, string filename, string d folder = destinationFolder }); - _client.Timeout = TimeSpan.FromMinutes(5); + try + { + _client.Timeout = TimeSpan.FromMinutes(5); + } + catch (InvalidOperationException e) + { + // Likely "System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request." + _logger.LogDebug(e.Message); + } var response = await _client.PostAsync(url, new StreamContent(document)); var documentResponse = await response.Content.ReadAsAsync();