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

get_events returns error in `httr2::req_perform()` #94

Closed sketchkey closed 1 year ago

sketchkey commented 1 year ago

I was just asked this morning by a colleague if I'd ever seen a specific GFWR error before, and after re-running some previously working code it looks like it's a new issue with the events API. get_vessel_info works fine, but get_event just hangs for a while and then throws an error (reprex below is from the GFWR Readme example):

vessel_id <- get_vessel_info(query = 224224000, search_type = "basic", key = key)$id

get_event(event_type='port_visit',
          vessel = vessel_id,
          confidences = '4',
          key = key
)

After 5-10 mins the following error is given (I've included the backtrace output from rlang::last_error():

Error in `httr2::req_perform()`:
! Failed to parse error body with method defined in req_error()
Caused by error in `check_content_type()`:
! Unexpected content type 'text/plain'
Expecting 'application/json'
Or suffix '+json'
ℹ Override check with `check_type = FALSE`
Run `rlang::last_error()` to see where the error occurred.
---
Backtrace:
  1. gfwr::get_event(...)
  7. httr2::req_perform(.)
 11. httr2:::error_body(req, resp)
 18. httr2:::req_policy_call(req, "error_body", list(resp), default = NULL)
 20. gfwr (local) `<fn>`(`<httr2_rs>`)
 21. httr2::resp_body_json(resp)
 22. httr2:::check_content_type(resp, types = "application/json", suffix = "+json", check_type = check_type)

I also tried force-updating the GFWR package via devtools, but the issue still persists!

tclavelle commented 1 year ago

Hi @sketchkey - Thanks for submitting this issue. Our APIs recently updated how they deliver error messages and we were slow in merging the corresponding fix to gfwr. This was corrected earlier this week, so try updating gfwr via devtools again and see if the error persists.

sketchkey commented 1 year ago

Yep updated via devtools and problem solved — many thanks!

tclavelle commented 1 year ago

Great! Thanks again for submitting the issue.