From 2d6eff9cb3a5dd5d0cc2cd452097a132c6d693ea Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Sat, 16 Aug 2025 14:50:19 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20catch=20=E4=B8=80=E4=B8=8B=E4=BC=81?= =?UTF-8?q?=E9=B9=85=E7=89=A9=E6=B5=81=E7=9A=84=E4=B8=8A=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=AF=B7=E6=B1=82=EF=BC=8C=E9=81=BF=E5=85=8D=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=E9=87=8D=E8=AF=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #13730 --- .../Services/Web/GameDataReportService.cs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/MaaWpfGui/Services/Web/GameDataReportService.cs b/src/MaaWpfGui/Services/Web/GameDataReportService.cs index 3b0fb6c53b..90de62b25d 100644 --- a/src/MaaWpfGui/Services/Web/GameDataReportService.cs +++ b/src/MaaWpfGui/Services/Web/GameDataReportService.cs @@ -73,23 +73,30 @@ namespace MaaWpfGui.Services.Web private static async Task TryPostAsync(string targetUrl, HttpContent content, Dictionary headers) { - int currentBackoff = InitialBackoffMs; - for (int attempt = 1; attempt <= MaxRetryPerDomain; attempt++) + try { - var response = await Instances.HttpService.PostAsync(new(targetUrl), content, headers); - - switch ((int)response.StatusCode) + int currentBackoff = InitialBackoffMs; + for (int attempt = 1; attempt <= MaxRetryPerDomain; attempt++) { - case 200: - return response; - case >= 500 and < 600: - await Task.Delay(currentBackoff); - currentBackoff = (int)(currentBackoff * 1.5); - continue; - default: - return response; + var response = await Instances.HttpService.PostAsync(new(targetUrl), content, headers); + + switch ((int)response.StatusCode) + { + case 200: + return response; + case >= 500 and < 600: + await Task.Delay(currentBackoff); + currentBackoff = (int)(currentBackoff * 1.5); + continue; + default: + return response; + } } } + catch (Exception ex) + { + _logger.Error(ex, "Error during HTTP POST request to {TargetUrl}", targetUrl); + } return null; }