using System.Net.Http.Json; using GB5Shared.Telemetry; using Microsoft.Extensions.Logging; namespace AutomationBLL.DocumentFlow; public class AckCallbackClient : IAckCallbackClient { private readonly IHttpClientFactory _httpFactory; private readonly ILogger _logger; public AckCallbackClient(IHttpClientFactory httpFactory, ILogger logger) { _httpFactory = httpFactory; _logger = logger; } public async Task SendAsync(string callbackUrl, string orderId, string ackReference, CancellationToken ct = default) { try { var http = _httpFactory.CreateClient("ackcallback"); using var response = await http.PostAsJsonAsync(callbackUrl, new { OrderId = orderId, AckReference = ackReference }, ct) .ConfigureAwait(false); response.EnsureSuccessStatusCode(); } catch (Exception ex) { // Non-fatal by design — the run itself already completed successfully; a failed // ack-writeback callback must not roll that back. Logged for manual follow-up. GB5Trace.RecordError(ex, "ack-callback-failed"); _logger.LogWarning(ex, "AckCallbackClient: failed to POST to {CallbackUrl} for OrderId {OrderId}", callbackUrl, orderId); } } }