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());