Skip to content

Commit

Permalink
Raise error if credentials are invalid (fix #110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrin Leinweber authored and Katrin Leinweber committed Aug 7, 2019
1 parent e148c9c commit d7a2526
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: BacDiveR
Title: Programmatic Interface For The Bacterial Diversity
Metadatabase by DSMZ
Version: 0.9.0
Version: 0.9.1
Authors@R:
person(given = "Katrin",
family = "Leinweber",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
### Fixed
### Security


## BacDiveR 0.9.1

### Fixed

- Expose a previously silent download error (#110; Thanks to @jfy133!)

## BacDiveR 0.9.0

All notable changes to this project will be documented in this file.
Expand Down
8 changes: 7 additions & 1 deletion R/util-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ download <- function(URL, user = get_credentials()[1], password = get_credential

response <- httr::GET(URL, httr::authenticate(user, password))
payload <- httr::content(response, as = "text", encoding = "UTF-8")
jsonlite::fromJSON(payload)
data <- jsonlite::fromJSON(payload)

if (response$status_code == 403) {
stop(paste(data, "\nCheck your .Renviron file, and try copy-pasting your login credentials into https://bacdive.dsmz.de/api/bacdive/ to test them. Correct as necessary and try your data download again."))
} else {
return(data)
}
}
4 changes: 4 additions & 0 deletions tests/testthat/test-download.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("Downloading without preper credentials raises an error", {
random <- sample(letters, 8)
expect_error(download(construct_url(717), user = random, password = random))
})

0 comments on commit d7a2526

Please sign in to comment.