Skip to content

Commit 39df056

Browse files
more robust error msg
1 parent 7754d9a commit 39df056

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

R/iidda.api/R/bindings.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ production = NULL
2525

2626
handle_iidda_response <- function(x) {
2727
if (x$status_code == 400L) {
28-
api_err_msg = unlist(httr::content(x)$detail
29-
, use.names = FALSE
30-
, recursive = TRUE
31-
)
32-
err_tmplt = "The IIDDA API returned the following error:\n %s\nThis documentation might be of interest:\n %s"
33-
err_msg = sprintf(err_tmplt, api_err_msg, iidda.api::docs_url_staging)
34-
stop(err_msg)
28+
response_content = httr::content(x)
29+
if ("detail" %in% names(response_content)) { ## condition needed because 400s can originate outside of the iidda api
30+
api_err_msg = unlist(response_content$detail
31+
, use.names = FALSE
32+
, recursive = TRUE
33+
)
34+
err_tmplt = "The IIDDA API returned the following error:\n %s\nThis documentation might be of interest:\n %s"
35+
err_msg = sprintf(err_tmplt, api_err_msg, iidda.api::docs_url_staging)
36+
stop(err_msg)
37+
}
3538
} else if (x$status_code == 404L) {
3639
msg = sprintf("404 Not Found. The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. This documentation might be of interest:\n %s", iidda.api::docs_url_staging)
3740
stop(msg)
38-
} else if (x$status_code != 200L) {
41+
}
42+
if (x$status_code != 200L) {
3943
err_tmplt = "Something went wrong with the IIDDA API.\nStatus code: %s\nRequest URL: %s\nThis documentation might be of interest:\n %s"
4044
err_msg = sprintf(err_tmplt, x$status_code, x$url, iidda.api::docs_url_staging)
4145
stop(err_msg)

R/iidda.api/R/parse.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ set_dict_names = function(x) {
33
}
44
get_dict = function() {
55
dict = suppressWarnings({iidda.api::ops_staging$data_dictionary()})
6+
#"https://raw.githubusercontent.com/canmod/iidda/main/global-metadata/data-dictionary.json"
67
set_dict_names(dict)
78
}
89

9-
## converted to messager objects in zzz.R
10+
## converted to message objects in zzz.R
1011
messages = list(
1112
conversion = list(
1213
"Now converting some fields from character to numeric or date. ",

R/iidda.api/vignettes/Provenance.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ knitr::opts_chunk$set(
1414
)
1515
```
1616

17-
In this vignette we illustrate how to investigate the provenance of a particular record in the a dataset obtained from the API. We use an example of a surprisingly late smallpox record in the CANMOD data.
17+
In this vignette we illustrate how to investigate the provenance of a particular record in the a dataset obtained from the API. We use an example of a surprisingly late smallpox record in the CANDID data.
1818

1919
![](images/Smallpox_virus_virions_TEM_PHIL_1849.JPG){width="60%"}
2020

0 commit comments

Comments
 (0)