From 58ffaa492470f5e77e602e734d07b7563a7e3e24 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:13:35 +0900 Subject: [PATCH] Fix: Fixed SocketException in GitHelpers.RequireGitAuthenticationAsync (#14769) --- src/Files.App/Utils/Git/GitHelpers.cs | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Files.App/Utils/Git/GitHelpers.cs b/src/Files.App/Utils/Git/GitHelpers.cs index 5aea9c2b007cd..2e2f534f064e5 100644 --- a/src/Files.App/Utils/Git/GitHelpers.cs +++ b/src/Files.App/Utils/Git/GitHelpers.cs @@ -535,27 +535,27 @@ public static async Task RequireGitAuthenticationAsync() client.DefaultRequestHeaders.Add("Accept", "application/json"); client.DefaultRequestHeaders.Add("User-Agent", "Files App"); - HttpResponseMessage codeResponse; + JsonDocument? codeJsonContent; try { - codeResponse = await client.PostAsync( + var codeResponse = await client.PostAsync( $"https://github.com/login/device/code?client_id={_clientId}&scope=repo", new StringContent("")); - } - catch - { - await DynamicDialogFactory.GetFor_GitHubConnectionError().TryShowAsync(); - return; - } - if (!codeResponse.IsSuccessStatusCode) - { - await DynamicDialogFactory.GetFor_GitHubConnectionError().TryShowAsync(); - return; - } + if (!codeResponse.IsSuccessStatusCode) + { + await DynamicDialogFactory.GetFor_GitHubConnectionError().TryShowAsync(); + return; + } - var codeJsonContent = await codeResponse.Content.ReadFromJsonAsync(); - if (codeJsonContent is null) + codeJsonContent = await codeResponse.Content.ReadFromJsonAsync(); + if (codeJsonContent is null) + { + await DynamicDialogFactory.GetFor_GitHubConnectionError().TryShowAsync(); + return; + } + } + catch { await DynamicDialogFactory.GetFor_GitHubConnectionError().TryShowAsync(); return;