From 44d6e0c4442222c520fc0ee558d7be66cb766283 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sat, 22 Apr 2023 17:40:13 -0400 Subject: [PATCH] Workaround for invalid CA2000 warning --- .../Core/AbstractHttpClientFactory.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/AbstractHttpClientFactory.cs b/src/Tgstation.Server.Host/Core/AbstractHttpClientFactory.cs index d3bfc28ab7..16e1b35fe5 100644 --- a/src/Tgstation.Server.Host/Core/AbstractHttpClientFactory.cs +++ b/src/Tgstation.Server.Host/Core/AbstractHttpClientFactory.cs @@ -46,16 +46,25 @@ namespace Tgstation.Server.Host.Core public IHttpClient CreateClient() { logger.LogTrace("Creating client..."); - var client = new Tgstation.Server.Common.HttpClient( - httpClientFactory.CreateClient()); + var innerClient = httpClientFactory.CreateClient(); try { - client.DefaultRequestHeaders.UserAgent.Add(assemblyInformationProvider.ProductInfoHeaderValue); - return client; + var client = new Tgstation.Server.Common.HttpClient(httpClientFactory.CreateClient()); + innerClient = null; // CA2000 + try + { + client.DefaultRequestHeaders.UserAgent.Add(assemblyInformationProvider.ProductInfoHeaderValue); + return client; + } + catch + { + client.Dispose(); + throw; + } } catch { - client.Dispose(); + innerClient?.Dispose(); throw; } }