R/safedata_network.R
try_to_download.Rd
This function tries to fetch the HEAD for the resource and handles failure to resolve (such as a bad safedata API url), timeouts and then actual HTTP error codes. If none of those occur, the resource is downloaded.
try_to_download(url, local_path = NULL, timeout = 10)
The URL to download.
A path to a file in which to save the URL content.
The waiting time in seconds before a request should timeout.
An response
object or a boolean showing if the
download attempt was successful.
If the download fails, the function returns FALSE and the return value
attribute 'fail_msg' is used to provide details. Otherwise, an
response
object is returned containing the resource. If a
local path is provided, the resource is downloaded to that path and the
function returns TRUE to indicate success.
This function contains code to simulate network failures of varying kinds (no network, no API, specific resource unavailable) for use in unit testing that the safedata package handles theses errors gracefully.