From a170168f2176712defac592b8d5b5398be8065cc Mon Sep 17 00:00:00 2001 From: Adriano Serighelli Date: Tue, 30 Sep 2025 13:21:20 -0300 Subject: [PATCH] =?UTF-8?q?Condi=C3=A7=C3=B5es=20de=20parada=20e=20retry.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index 9791a9d..3e39b0a 100644 --- a/Program.cs +++ b/Program.cs @@ -145,16 +145,38 @@ internal class Plat_integ using var response = await client.PostAsync(endpoint, conteudo, ct); string resposta = await response.Content.ReadAsStringAsync(); - if ((int)response.StatusCode == 429) // limite da API + if ((int)response.StatusCode >= 400) { - Console.WriteLine("⚠️ Limite de requisições atingido. Aguardando próximo minuto..."); + try + { + VerificarRespostaSOAP(resposta); + } + catch (SoapFaultException ex) + { + if (ex.ErrorCode == "2003") // limite de requisições + { var now = DateTime.UtcNow; var delay = 60000 - (now.Second * 1000 + now.Millisecond); - await Task.Delay(delay, ct); - continue; // tentar de novo sem contar como falha + Console.WriteLine($"!! Limite de requisições atingido. Aguardando até {DateTime.Now.AddMilliseconds(delay)}"); + await Task.Delay(delay, ct); // tentar de novo sem contar como falha + continue; } - - response.EnsureSuccessStatusCode(); + if (ex.ErrorCode == "4001") // Dados não encontrados + { + errosPersistentes.Add($"{perfil._Cod_5min};{perfil._Codigo_SCDE};SOAP Fault: {ex.ErrorCode};{ex.ErrorMessage.Replace("\n", "-n-")}"); + break; + } + if (ex.ErrorCode == "2001") // Sem acesso + { + errosPersistentes.Add($"{perfil._Cod_5min};{perfil._Codigo_SCDE};SOAP Fault: {ex.ErrorCode};{ex.ErrorMessage.Replace("\n", "-n-")}"); + break; + } + else + { + throw; + } + } + } string resposta = await response.Content.ReadAsStringAsync(ct); await ProcessarXMLAsync(resposta, await dataSource.OpenConnectionAsync());