Skip to content

Commit

Permalink
FIX unknown status code (#567) (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javdat authored and hadley committed Apr 28, 2019
1 parent 45e6e28 commit 417411b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,5 +1,8 @@
# httr (development version)

* `http_status()` now throws the correct error message if http status code is
not in the list of known codes (@Javdat, #567).

* `RETRY()` now throws the correct error message if an error occurs during the
request (@austin3dickey, #581).

Expand Down
5 changes: 3 additions & 2 deletions R/response-status.r
Expand Up @@ -46,11 +46,12 @@ status_code.numeric <- function(x) x
http_status <- function(x) {
status <- status_code(x)

status_desc <- http_statuses[[as.character(status)]]
if (is.na(status_desc)) {
if (!status %in% names(http_statuses)) {
stop("Unknown http status code: ", status, call. = FALSE)
}

status_desc <- http_statuses[[as.character(status)]]

status_types <- c(
"Information", "Success", "Redirection", "Client error",
"Server error"
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-http-condition.R
Expand Up @@ -13,3 +13,7 @@ test_that("status converted to errors", {
test_that("task adds informative message", {
expect_error(stop_for_status(300, "download"), "Failed to download.")
})

test_that("unknown status converted to error", {
expect_error(stop_for_status(10000), "Unknown http status code: 10000", fixed = TRUE)
})

0 comments on commit 417411b

Please sign in to comment.