tests/testthat/test-http-error.R

context("http_error")

test_that("http_error works with urls", {
  skip_httpbin()
  expect_false(http_error("http://httpbin.org/status/200"))
  expect_true(http_error("http://httpbin.org/status/404"))
})

test_that("http_error works with responses", {
  skip_httpbin()
  r200 <- GET("http://httpbin.org/status/200")
  expect_false(http_error(r200))

  r404 <- GET("http://httpbin.org/status/404")
  expect_true(http_error(r404))
})

test_that("http_error works with integers", {
  expect_false(http_error(200L))
  expect_true(http_error(404L))
})

Try the httr package in your browser

Any scripts or data that you put into this service are public.

httr documentation built on Aug. 15, 2023, 9:08 a.m.