inbo / etn

R package to access data from the European Tracking Network
https://inbo.github.io/etn/
MIT License
6 stars 5 forks source link

`check_opencpu_response()` should check for content type of API response #300

Closed PietrH closed 2 weeks ago

PietrH commented 3 weeks ago

Currently check_opencpu_response() only checks for the HTTP status code, but it could also check for the content type.

During #297 , I encountered a case where the content type was binary causing extract_temp_key() to return NA without an error.

Either of these functions should have thrown an error here instead.

The API response was binary because I was passing unsupported arguments to etnservice via the request body

PietrH commented 2 weeks ago

Both check_opencpu_response() and forward_to_api() (via check_opencpu_response() return the R error as they should and stop operation...

So while I can replicate the OpenCPU binary response with:

httr::POST(
    url = "https://opencpu.lifewatch.be/library/etnservice/R/write_dwc/",
    body = list(credentials = get_credentials(),
                animal_project_code = "2014_demer",
                directory = "."),
    encode = "json"
  )

I can't actually replicate the no error behaviour.

PietrH commented 2 weeks ago

Was I getting a different error because of the 403 I was getting? (because functions needed to start with connect_, get_ or list_, now also write_?

But even then the function should have returned an error with the message:

Error: API request failed: Client error: (403) Forbidden