GlobalFishingWatch / gfwr

R package for accessing data from Global Fishing Watch APIs
https://globalfishingwatch.github.io/gfwr/
Apache License 2.0
58 stars 7 forks source link

update error handling for get_raster #87

Closed natemiller closed 1 year ago

natemiller commented 1 year ago

Currently get_raster has a date range limit of 366 days. Currently when users request longer time ranges the error message is difficult to interpret, though the API returns a reasonable message.

Turns out the error handling in gist_error_body doesn't work with the error structure returned by the 4wings API

This is the current form

gist_error_body <- function(resp) {
  body <- httr2::resp_body_json(resp)
  message <- body$message
  if(length(message) > 1){
    message <- purrr::map_chr(message, purrr::pluck, 'detail')
  }
  message
}

the following function does work, but I am not certain if it works with other API endpoints. We need to check. Note I have changed to messages and we need to access the messages list using [[ 1]].


gist_error_body <- function(resp) {
  body <- httr2::resp_body_json(resp)
  messages <- body$messages
  if(length(messages[[1]]) > 1){
    messages <- purrr::map_chr(messages, purrr::pluck, 'detail')
  }
  messages
}

@tclavelle  Could you take a look at this given you explored the error handling for other API endpoints?
natemiller commented 1 year ago

Sorry should have placed this in Issue #83 . We can either move this or just make sure to close both issues when it is resolved

natemiller commented 1 year ago

Closed by #88