DataONEorg / rdataone

R package for reading and writing data at DataONE data repositories
http://doi.org/10.5063/F1M61H5X
36 stars 19 forks source link

Handle errors returned from `auth_get()` function #264

Closed gothub closed 3 years ago

gothub commented 3 years ago

@mbjones

The functions in auth_request.R: auth_get(), auth_post(), ... make calls to the httr package that can return network errors, for example, a run of the following script:

library(dataone)
cn_prod <- CNode("PROD")
mn_iarc <- getMNode(cn_prod, "urn:node:IARC")
from <- D1Client(cn_prod, mn_iarc)
getDataObject(from, "dcx_d671d973-09b3-41d7-b7e2-acbf2f638627_2")

returned this error:

<simpleError in curl::curl_fetch_memory(url, handle = handle): SSL: certificate subject name (*.nkn.uidaho.edu) does not match target host name 'dataone.northwestknowledge.net'>

This error was not handled by getDataObject, so caused the script to fail.

Either wrap calls to the auth* functions or handle the errors internally in the auth* functions.

I would vote for wrapping the auth* functions in the calling routines, so that the calling routine can decide what action to take.

What approach would be used if the errors are captured and handled internally to the auth* funcitons?

gothub commented 3 years ago

From slack:

metamattj  35 minutes ago
so, better to wrap the network call inside auth_get in a try block, and, if it fails, still return an appropriate error code
metamattj  34 minutes ago
that way calling code doesn’t have to worry about the network errors, and can assume the status code will be accurate
jeanetteclark commented 3 years ago

@gothub here is one approach: https://github.com/jeanetteclark/rdataone/commit/3952742c0c1a95998fa175538bb302705c041b43

mbjones commented 3 years ago

I tested @jeanetteclark and your approach looks good to me.

gothub commented 3 years ago

Thanks @jeanetteclark - I tested both getDataPackage() and getDataObject(). The above code succeeds with the fix you made.

jeanetteclark commented 3 years ago

@gothub did you test on an object where you expect it to succeed right away? It just occurred to me I only tested on the failing case

gothub commented 3 years ago

@jeanetteclark good point - I just now checked used a data object that didn't have any network errors and that worked as well.

gothub commented 3 years ago

Closed from issue #266