From 325a0e8019b4c55dceb81fc22c1d59c08d12ac43 Mon Sep 17 00:00:00 2001 From: Christiaan Bloemendaal Date: Sat, 3 Feb 2024 22:47:33 +0100 Subject: [PATCH] fix: catching exceptions when sending --- .../Sources/Clients/CustomHttpClient.Get.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Mangarr.Stack/Sources/Clients/CustomHttpClient.Get.cs b/src/Mangarr.Stack/Sources/Clients/CustomHttpClient.Get.cs index 67a65d7..6cd758f 100644 --- a/src/Mangarr.Stack/Sources/Clients/CustomHttpClient.Get.cs +++ b/src/Mangarr.Stack/Sources/Clients/CustomHttpClient.Get.cs @@ -108,7 +108,17 @@ public async Task> GetBuffer(string requestUri, CancellationToken public async Task> Get(string requestUri, CancellationToken ct = default) { HttpClient httpClient = CreateClient(); - using HttpResponseMessage response = await httpClient.SendAsync(CreateGetRequest(requestUri), ct); + HttpResponseMessage response; + + try + { + response = await httpClient.SendAsync(CreateGetRequest(requestUri), ct); + } + catch (Exception e) + { + return Result.Fail(new ExceptionalError(e)) + .WithReason(new UrlReason(requestUri)); + } try { @@ -145,7 +155,17 @@ public async Task> Get(string requestUri where TConcrete : TAbstract { HttpClient httpClient = CreateClient(); - using HttpResponseMessage response = await httpClient.SendAsync(CreateGetRequest(requestUri), ct); + HttpResponseMessage response; + + try + { + response = await httpClient.SendAsync(CreateGetRequest(requestUri), ct); + } + catch (Exception e) + { + return Result.Fail(new ExceptionalError(e)) + .WithReason(new UrlReason(requestUri)); + } try {