diff --git a/src/Server/Program.cs b/src/Server/Program.cs index b4435a7..39be968 100755 --- a/src/Server/Program.cs +++ b/src/Server/Program.cs @@ -91,16 +91,23 @@ if (IPayment._PaymentType == PaymentType.StripeIntent) { RsaSecurityKey? PublicKey = null; using (HttpClient client = new HttpClient()) { while (PublicKey == null) { - HttpResponseMessage PublicKeyResponse = await client.GetAsync("https://auth.mistox.com/api/auth/publickey"); - if (PublicKeyResponse.IsSuccessStatusCode) { - string publicKey = await PublicKeyResponse.Content.ReadAsStringAsync(); - RSA rsa = RSA.Create(); - rsa.ImportFromPem(publicKey); - PublicKey = new RsaSecurityKey(rsa); - } else { + try { + HttpResponseMessage PublicKeyResponse = await client.GetAsync("https://auth.mistox.com/api/auth/publickey"); + if (PublicKeyResponse.IsSuccessStatusCode) { + string publicKey = await PublicKeyResponse.Content.ReadAsStringAsync(); + RSA rsa = RSA.Create(); + rsa.ImportFromPem(publicKey); + PublicKey = new RsaSecurityKey(rsa); + } else { + await Task.Delay(2000); // sleep the main thread for 2 seconds before sending another request. Prevent DDOS of my own equiptment + Console.WriteLine("auth.mistox.com returned error code: " + PublicKeyResponse.StatusCode); + } + } catch (Exception e) { await Task.Delay(2000); // sleep the main thread for 2 seconds before sending another request. Prevent DDOS of my own equiptment + Console.WriteLine("Error loading public key: " + e.InnerException?.Message); } } + Console.WriteLine("PublicKey loaded"); } builder.Services.AddAuthentication(options => {