TsgcWSCircuitBreaker › Events › OnFallback
Fired just before a fallback response is returned while the circuit is Open; the handler may replace the payload.
property OnFallback: TsgcCircuitBreakerOnFallback;
// TsgcCircuitBreakerOnFallback = procedure(Sender: TObject; const aKey: string; var aResponse: string) of object
—
Fires only when Fallback.Enabled is True and the breaker is about to serve a fallback response for a rejected call. The aResponse var parameter arrives pre-populated in this order: the last successful response for the key (when Fallback.UseLastSuccess is True), otherwise Fallback.CachedResponse, otherwise Fallback.CustomMessage. The handler is free to mutate aResponse — for example to inject the current key into a JSON body, or to return a per-tenant maintenance message. The string returned from the handler is what the caller ultimately sees. Runs synchronously on the thread that made the call; keep the handler fast (no network I/O). When no handler is attached, the pre-populated aResponse is returned as-is.
procedure TForm1.CircuitFallback(Sender: TObject; const aKey: string;
var aResponse: string);
begin
// Inject the affected host into a JSON body so the caller knows what failed
aResponse := Format(
'{"error":"service unavailable","service":"%s","retry_after":30}',
[aKey]);
end;