From 0c7589c177f2f2c001f3afe2f073572a217b6050 Mon Sep 17 00:00:00 2001 From: Gervasio Marchand Date: Fri, 9 Dec 2022 18:19:15 -0300 Subject: [PATCH] catch errors pulling data from other instances --- src/Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 560b80f..70b4f5f 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -36,14 +36,15 @@ await Parallel.ForEachAsync(sitesTags, parallelOptions, async (st, _) => { var (site, tag) = st; Console.WriteLine($"Fetching tag #{tag} from {site}"); - var response = await client.GetAsync($"https://{site}/tags/{tag}.json"); + HttpResponseMessage? response = null; try { + response = await client.GetAsync($"https://{site}/tags/{tag}.json"); response.EnsureSuccessStatusCode(); } catch (Exception e) { - Console.WriteLine($"Error fetching tag, status code: {response.StatusCode}. Error: {e.Message}"); + Console.WriteLine($"Error fetching tag, status code: {response?.StatusCode}. Error: {e.Message}"); return; }