api_error_handler: Error handler

Description Usage Arguments See Also Examples

View source: R/errors.R

Description

Error handler

Usage

1
api_error_handler(.data, fun)

Arguments

.data

Result of a call to api

fun

A function, either defined in the session, or a function available in loaded or name-spaced packges

See Also

Other dsl: api_body(), api_config(), api_path(), api_query(), api_template(), api(), auth

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
# Use functions from httr
api('http://httpbin.org/status/503') %>%
 api_error_handler(stop_for_status)

api('http://httpbin.org/status/404') %>%
 api_error_handler(warn_for_status)

# Custom error handling functions
my_stop <- function(x) {
  if (x$status > 200) {
     warning("nope, try again", call. = FALSE)
  }
}
api("http://httpbin.org/status/404") %>%
 api_error_handler(my_stop)

## End(Not run)

sckott/request documentation built on June 22, 2020, 4:50 a.m.