Network failures happen. Polly adds retry, circuit breaker, and timeout policies automatically. Install: dotnet add package Polly dotnet add package Microsoft.Extensions.Http.Polly Add to HttpClient: // Program.cs builder.Services.AddHttpClient(“MyAPI”, client => { client.BaseAddress = new Uri(“https://api.example.com”); }) .AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(3, attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt))) ) .AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(5, TimeSpan.FromMinutes(1)) ); Usage: public class MyService { private readonly […]
Tag: Fault Tolerance
Handle AJAX Errors Properly: Retry Logic with Exponential Backoff
Your AJAX calls fail randomly due to network hiccups or server load? Implement smart retry logic that actually works. The Problem with Basic Retry: // Bad: Immediate retry can make things worse function badRetry(url, maxAttempts) { for (let i = 0; i < maxAttempts; i++) { try { return await fetch(url); } catch (error) { […]

