ropensci / ruODK

ruODK: An R Client for the ODK Central API
https://docs.ropensci.org/ruODK/
GNU General Public License v3.0
42 stars 13 forks source link

Suggestion: Better error message when a form_schema of an unpublished form is requested #103

Closed dmenne closed 3 years ago

dmenne commented 3 years ago

When testing, often forget that form_schema and others must be used on published forms. So a form_schema of a draft form gives the error message:

Fehler: Problem with `mutate()` input `ruodk_name`.
x Objekt 'path' nicht gefunden
i Input `ruodk_name` is ``%>%`(...)`

which can be a bit confusing.

Suggestion something like: Error: "this form does not exist"

florianm commented 3 years ago

The new test server even has an unpublished draft form.

I can replicate the non-informative error message:

library(ruODK)
  fs0 <- ruODK::form_schema(
    flatten = FALSE,
    parse = FALSE,
    pid = get_test_pid(),
    fid = "Locations_draft",
    url = get_test_url(),
    un = get_test_un(),
    pw = get_test_pw(),
    odkc_version = get_test_odkc_version()
  )
#> ℹ Form schema v1
#> Error: Problem with `mutate()` input `ruodk_name`.
#> x object 'path' not found
#> ℹ Input `ruodk_name` is ``%>%`(...)`.

Created on 2020-11-09 by the reprex package (v0.3.0)

ODK Central API behaviour

Draft forms return an empty response on the "published form schema" endpoint. There is a draft form schema endpoint, so ruODK::form_schema should either know in advance whether the form schema is a draft and toggle API URL paths, or fall back to it in case the former API (published form) returns an empty response.

https://odkcentral.docs.apiary.io/#reference/forms-and-submissions/'-individual-form/getting-form-schema-fields https://odkcentral.docs.apiary.io/#reference/forms-and-submissions/'-draft-form/getting-draft-form-schema-fields

ruODK behaviour

In any case, ruODK should try the published form schema API first and return that if that worked. This will add minimal performance penalty to the 99% use case ("form is published").

For unpublished forms, ruODK should fall back to read the draft form schema. This adds a second API call to this less frequently expected use case, rather than checking form details in a separate API call ahead of the form schema API call.