Introduction to the fauxpas package

  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE

fauxpas does http errors!

To see example of fauxpas usage in other packages, check out the code within any of:

There are a lot of functions in this package. Don't be scared away by that. There are a few major sets of functions that are easy to understand and use:

fauxpas uses httpcode under the hood - which holds all the info about HTTP status codes.


CRAN version


Dev version

# install.packages("remotes")

Find classes for a HTTP status code

When using fauxpas in another package I personally like to use the HTTP* classes.

Since these are named with their HTTP reason (e.g. HTTPGatewayTimeout), it's not super straightforward to find them with a status code, which is what one always has as a response from a server. A good way to find these is with a new function find_error_class(). Just pass the function a HTTP status code and it will find the matching class.

(x <- find_error_class(418))

Which returns the matching error class object, with which you can initialize a new object:


If you pass it a status code it doesn't know about it errors

#> Error in find_error_class(999) : no method found for 999

Use fauxpas with HTTP clients


cli <- HttpClient$new("")
res <- cli$get()
#> Error: Request-URI Too Long (HTTP 414).
#> Error: Request-URI Too Long (HTTP 414).
x <- HTTPRequestURITooLong$new()
#> Error: Request-URI Too Long (HTTP 414).
#> - The server is refusing to service the request because the Request-URI is
#>    longer than the server is willing to interpret. This rare condition is only likely
#>    to occur when a client has improperly converted a POST request to a GET request
#>    with long query information, when the client has descended into a URI black hole
#>    of redirection (e.g., a redirected URI prefix that points to a suffix of itself),
#>    or when the server is under attack by a client attempting to exploit security
#>    holes present in some servers using fixed-length buffers for reading or
#>    manipulating the Request-URI.


h <- curl::new_handle()
resp <- curl::curl_fetch_memory("", h)
#> Error: Not Found (HTTP 404).
#> Error: Not Found (HTTP 404).
x <- HTTPNotFound$new()
#> Error:  Not Found (HTTP 404).
#>  - The server has not found anything matching the Request-URI. No indication is
#> given of whether the condition is temporary or permanent. The 410 (Gone) status
#> code SHOULD be used if the server knows, through some internally configurable
#> mechanism, that an old resource is permanently unavailable and has no forwarding
#> address. #> This status code is commonly used when the server does not wish to
#> reveal exactly why the request has been refused, or when no other response is
#> applicable.


res <- GET("")
#> Error: Method Not Allowed (HTTP 405).
x <- HTTPMethodNotAllowed$new()
#> Error: Method Not Allowed (HTTP 405).
#>  - The method specified in the Request-Line is not allowed for the resource
#> identified by the Request-URI. The response MUST include an Allow header
#> containing a list of valid methods for the requested resource.

Try the fauxpas package in your browser

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

fauxpas documentation built on April 14, 2020, 7:16 p.m.