ropensci / wateRinfo

R package to download time series data from waterinfo.be
https://docs.ropensci.org/wateRinfo
MIT License
13 stars 3 forks source link

More informative error message when credit system limits are exceeded #80

Closed rogiersbart closed 4 years ago

rogiersbart commented 4 years ago

I have a small suggestion that might improve the experience of new users: Currently the error message when credit system limits are exceeded is not particularly helpful. When I encountered it first, I had the impression something was going wrong with the xml parsing of the returned data, not really with the credit limits. In the meantime I do have access to a token, but it would be very helpful if these errors could be caught, and a message could be provided pointing the user to the token and credit system information in the help files or website.

Below a reprex, of which I think it represents this exceedence of credit system limits:

library(wateRinfo)
lapply(
  get_stations("water_level", "day")$ts_id,
  get_timeseries_tsid,
  from = "1990-01-01",
  to = "2020-03-01"
)
#> No encoding supplied: defaulting to UTF-8.
#> Error: lexical error: invalid char in json text.
#>                                        <?xml version="1.0" ?><Exceptio
#>                      (right here) ------^

Created on 2020-03-13 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.6.3 (2020-02-29) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate Dutch_Belgium.1252 #> ctype Dutch_Belgium.1252 #> tz Europe/Paris #> date 2020-03-13 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> askpass 1.1 2019-01-13 [1] CRAN (R 3.6.1) #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1) #> callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2) #> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.3) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1) #> curl 4.3 2019-12-02 [1] CRAN (R 3.6.1) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1) #> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.1) #> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.3) #> dplyr 0.8.5 2020-03-07 [1] CRAN (R 3.6.3) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.2) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1) #> glue 1.3.2 2020-03-12 [1] CRAN (R 3.6.3) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.1) #> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.2) #> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.2) #> lubridate 1.7.4 2018-04-11 [1] CRAN (R 3.6.1) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1) #> openssl 1.4.1 2019-07-18 [1] CRAN (R 3.6.1) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2) #> processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.2) #> ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.3) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) #> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1) #> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.1) #> rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.3) #> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.2) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.3) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.1) #> tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.2) #> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.2) #> vctrs 0.2.4 2020-03-10 [1] CRAN (R 3.6.3) #> wateRinfo * 0.3.0.9065 2020-03-13 [1] Github (ropensci/wateRinfo@c03e4be) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1) #> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.2) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2) #> #> [1] C:/Users/brogiers/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-3.6.3/library ```
peterdesmet commented 4 years ago

@rogiersbart thanks for reporting this! Unhelpful error messages are annoying.

@stijnvanhoey do you want to look into this?

stijnvanhoey commented 4 years ago

Thanks for the report, this should indeed be improved.

Actually it is the issue of the server returning XML instead of json. Note, we removed in https://github.com/ropensci/wateRinfo/commit/735bcba900cc7a00d2074524dd9649f7074b8d40 the support for XML-errors as it was mentioned the service would always return json.

It is a hard one to reproduce. @WillemMaetens, maybe you could provide an example of the (XML) message returned by the server in the situation when a client reaches the credit system limits?

@peterdesmet if you have the opportunity, feel free to add a PR. It is a matter of recycling the previous code of https://github.com/ropensci/wateRinfo/commit/735bcba900cc7a00d2074524dd9649f7074b8d40 and improve the error message to inform the user on the credit limit.

stijnvanhoey commented 4 years ago

See #81