TsgcWSCircuitBreaker › Properties › Fallback
Alternative payload returned through OnFallback while the circuit is Open.
property Fallback: TsgcCircuitBreakerFallback read FFallback
write SetFallback;
—
When Fallback.Enabled is True and Execute / ExecuteWithResult rejects a call (or the HTTP API client integration detects an Open circuit), the OnFallback event fires with a response initialized from the configured fallback source. Handlers may mutate the aResponse var parameter before it is returned to the caller. Sub-properties: Enabled (False by default — rejected calls simply return without firing OnFallback), CachedResponse (static payload returned while the circuit is Open — takes precedence over CustomMessage), CustomMessage (fallback payload used when CachedResponse is empty) and UseLastSuccess (when True, the last successful response observed for the key is served instead of the static payload). Typical use: return a cached last-known-good response or a static "maintenance mode" JSON body so downstream callers see degraded-but-functional behavior.
// Serve a safe JSON body when the circuit for an upstream API is Open
sgcWSCircuitBreaker1.Fallback.Enabled := True;
sgcWSCircuitBreaker1.Fallback.CachedResponse :=
'{"error":"service unavailable","retry_after":30}';
sgcWSCircuitBreaker1.Fallback.CustomMessage :=
'{"error":"ai service temporarily offline"}';
sgcWSCircuitBreaker1.Fallback.UseLastSuccess := True;