cloudyr / googleCloudStorageR

Google Cloud Storage API to R
https://code.markedmondson.me/googleCloudStorageR
Other
104 stars 29 forks source link

Custom class for gcs_get_object() 40x errors #153

Closed wlandau closed 2 years ago

wlandau commented 2 years ago

When I run tryCatch(googleCloudStorageR::gcs_get_object(...), error = function(condition_object) browser()), on an object that does not exist, I find that condition_object has class c("simpleError", "error", "condition"). Would it be possible to throw a more specific error class for HTML error codes 400-404? For https://github.com/ropensci/targets/pull/722, this would eliminate confusion with other kinds of errors in targets:::gcp_gcs_head().

wlandau commented 2 years ago

rlang::abort(..., class = "http_400") is a convenient alternative to stop(...) for this.

MarkEdmondson1234 commented 2 years ago

This looks like something that would be best done in googleAuthR or gargle, but will investigate.

MarkEdmondson1234 commented 2 years ago

For now its implemented here via

# https://adv-r.hadley.nz/conditions.html
abort_http <- function(status_code, msg = NULL){
  rlang::abort(paste0("http_",status_code), 
        message = paste(status_code, "error when attempting HTTP -", msg)
  )
}

It would be better in googleAuthR though

MarkEdmondson1234 commented 2 years ago

This was done in googleAuthR - thanks for idea.