Failing gracefully with API calls

Hi, could someone get me started making my program more fault-tolerant? Specifically I have a script that makes about 75 API calls and gathers the results. Sometimes, for various reasons, the API call doesn't work, returning various html error codes. How can I detect when this happens, perhaps make a note of it, and continue the program?

I'm attaching a typical example below. In this case it is the "fredr" function that makes the API request. Thank you!

Chicago Fed National Activity Index: Diffusion Index

raw <- fredr(
series_id = "CFNAIDIFF")
sbp_CFNAIDIFF <- raw %>%
transmute(date, date_type = "M",
var = "CFNAIDIFF", val = value)
if (do_remove_used) remove(raw)
l1 <- bind_rows(l1, sbp_CFNAIDIFF)

library(purrr) has helpful wrapper functions you can use to give your own functions modified behaviour, examples are safely,possibly etc, in your case insistently might be most appropriate.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.