Status codes below 400 are considered successful, others will trigger errors. Note that this is different from the httr package, which considers the 3xx status code errors as well.

http_stop_for_status(resp)

Arguments

resp

HTTP response from http_get(), http_head(), etc.

Value

The HTTP response invisibly, if it is considered successful. Otherwise an error is thrown.

Examples

httpbin <- webfakes::new_app_process(webfakes::httpbin_app())
afun <- async(function() {
  http_get(httpbin$url("/status/404"))$
    then(http_stop_for_status)
})

tryCatch(synchronise(afun()), error = function(e) e)
#> <async error: Not Found (HTTP 404).
#>  in *parent* callback of `http_get(httpbin$url("/status/404"))$then` at ?/?:?:?>