For a client that wants the body and does not care why a call failed. Every other field is still there for a client that does care, so reach for this when the failure is genuinely not actionable, not to avoid reading the envelope.
Arguments
- res
An envelope from
perform()or one of the convenience wrappers.
Details
Returns the body for ok and for stale. A stale envelope carries real
data that is merely past its freshness window, so returning NULL for it
would throw away the one thing the caller asked for. Branch on res$status
if the difference matters. Note that res$ok is FALSE for stale, which
is what keeps cached() from storing it.
Examples
body_or_null(status_ok(data = list(n = 1)))
#> $n
#> [1] 1
#>
body_or_null(status_stale(data = list(n = 1)))
#> $n
#> [1] 1
#>
body_or_null(status_error(source = "gnomAD"))
#> NULL