Decorator that catches a failure and returns value, or the result of
handler(cnd), instead of signalling it. Only errors are caught by default.
A caught condition ends the call, as with tryCatch().
Details
Stack it outside retry() and circuit_breaker() so the default is used only
once retries are spent or the circuit is open.
Examples
f := fallback(value = NA_real_) %@% function(x) {
if (x < 0) stop("negative") else sqrt(x)
}
f(4)
#> [1] 2
f(-1)
#> [1] NA
g := fallback(handler = function(cnd) conditionMessage(cnd)) %@%
function() stop("boom")
g()
#> [1] "boom"
# Use the default only after retries and the circuit breaker give up
fetch := fallback(value = NULL) %@%
circuit_breaker(failures = 3) %@%
retry(stop = stop_after_attempt(3)) %@%
function(url) stop("down")
fetch("x")
#> NULL
