Title: | HTTP Error Helpers |
---|---|
Description: | HTTP error helpers. Methods included for general purpose HTTP error handling, as well as individual methods for every HTTP status code, both via status code numbers as well as their descriptive names. Supports ability to adjust behavior to stop, message or warning. Includes ability to use custom whisker template to have any configuration of status code, short description, and verbose message. Currently supports integration with 'crul', 'curl', and 'httr'. |
Authors: | Scott Chamberlain [aut, cre] |
Maintainer: | Scott Chamberlain <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.4 |
Built: | 2024-11-01 04:09:33 UTC |
Source: | https://github.com/sckott/fauxpas |
Error class
behavior |
Behavior of the error. default: auto. See Details |
message_template |
A message template. optional. use whisker
templating. names to use are: reason and status. use in template
like |
call. |
(logical) indicating if the call should become part
of the error message. Default: |
message_template_verbose |
A verbose message template. optional.
use whisker templating. names to use are: reason, status, message.
use in template like |
muffle |
(logical) whether to not respond when status codes
in 1xx-3xx series. Default: |
Methods
do(response, mssg)
Execute condition, whether it be message, warning, or error.
response: is any response from crul, curl, or httr
Execute condition, whether it be message, warning, error, or your
own custom function. This method uses message_template_verbose
,
and uses it's default value.
mssg: character string message to include in call. ignored if
template does not have a message
entry
set_behavior(behavior)
Set behavior, same as setting behavior on initializing with $new()
stop - use stop
warning - use warning
message - use message
auto - toggle between stop
and message
depending
on the HTTP status code series. Defaults will be:
1xx: message
2xx: message
3xx: message
4xx: stop
5xx: stop
Of course, you can always override the defaults.
Error$new() # reset behavior (z <- Error$new()) z$set_behavior("warning") z
Error$new() # reset behavior (z <- Error$new()) z$set_behavior("warning") z
These error classes are for each HTTP error, and inherit from
the Error
class in this package.
In addition to what's available in Error
,
these classes have a single variable mssg
that is the very
verbose complete message describing the HTTP condition in detail.
You can include that message in your condition by using do_verbose
(see below)
Methods
In addition to the methods documented in Error
, these methods
also have:
do_verbose(response, template)
Execute condition, whether it be message, warning, or error.
response: is any response from crul, curl, or httr
Execute condition, whether it be message, warning, error, or your
own custom function. This method uses message_template_verbose
,
and uses it's default value.
template: a template to use for the verbose message, see Error
for details
HTTPRequestURITooLong$new( message_template = "{{reason}} ............ {{status}}", message_template_verbose = "{{reason}} .>.>.>.>.>.> {{status}}\n {{message}}" )
HTTPRequestURITooLong$new( message_template = "{{reason}} ............ {{status}}", message_template_verbose = "{{reason}} .>.>.>.>.>.> {{status}}\n {{message}}" )
Find error classes
find_error_class(status_code)
find_error_class(status_code)
status_code |
(numeric,integer) A status code |
an object of class R6ClassGenerator
. call $new()
to initialize a new instance
find_error_class(414) find_error_class(418) find_error_class(505) # initialize the class find_error_class(418)$new() # not found ## Not run: find_error_class(999)
find_error_class(414) find_error_class(418) find_error_class(505) # initialize the class find_error_class(418)$new() # not found ## Not run: find_error_class(999)
higher level error wrappers
http100(response, behavior = "auto", message_template, muffle = FALSE) http101(response, behavior = "auto", message_template, muffle = FALSE) http102(response, behavior = "auto", message_template, muffle = FALSE) http200(response, behavior = "auto", message_template, muffle = FALSE) http201(response, behavior = "auto", message_template, muffle = FALSE) http202(response, behavior = "auto", message_template, muffle = FALSE) http203(response, behavior = "auto", message_template, muffle = FALSE) http204(response, behavior = "auto", message_template, muffle = FALSE) http205(response, behavior = "auto", message_template, muffle = FALSE) http206(response, behavior = "auto", message_template, muffle = FALSE) http207(response, behavior = "auto", message_template, muffle = FALSE) http208(response, behavior = "auto", message_template, muffle = FALSE) http226(response, behavior = "auto", message_template, muffle = FALSE) http300(response, behavior = "auto", message_template, muffle = FALSE) http301(response, behavior = "auto", message_template, muffle = FALSE) http302(response, behavior = "auto", message_template, muffle = FALSE) http303(response, behavior = "auto", message_template, muffle = FALSE) http304(response, behavior = "auto", message_template, muffle = FALSE) http305(response, behavior = "auto", message_template, muffle = FALSE) http306(response, behavior = "auto", message_template, muffle = FALSE) http307(response, behavior = "auto", message_template, muffle = FALSE) http308(response, behavior = "auto", message_template, muffle = FALSE) http400(response, behavior = "auto", message_template, muffle = FALSE) http401(response, behavior = "auto", message_template, muffle = FALSE) http402(response, behavior = "auto", message_template, muffle = FALSE) http403(response, behavior = "auto", message_template, muffle = FALSE) http404(response, behavior = "auto", message_template, muffle = FALSE) http405(response, behavior = "auto", message_template, muffle = FALSE) http406(response, behavior = "auto", message_template, muffle = FALSE) http407(response, behavior = "auto", message_template, muffle = FALSE) http408(response, behavior = "auto", message_template, muffle = FALSE) http409(response, behavior = "auto", message_template, muffle = FALSE) http410(response, behavior = "auto", message_template, muffle = FALSE) http411(response, behavior = "auto", message_template, muffle = FALSE) http412(response, behavior = "auto", message_template, muffle = FALSE) http413(response, behavior = "auto", message_template, muffle = FALSE) http414(response, behavior = "auto", message_template, muffle = FALSE) http415(response, behavior = "auto", message_template, muffle = FALSE) http416(response, behavior = "auto", message_template, muffle = FALSE) http417(response, behavior = "auto", message_template, muffle = FALSE) http418(response, behavior = "auto", message_template, muffle = FALSE) http419(response, behavior = "auto", message_template, muffle = FALSE) http420(response, behavior = "auto", message_template, muffle = FALSE) http422(response, behavior = "auto", message_template, muffle = FALSE) http423(response, behavior = "auto", message_template, muffle = FALSE) http424(response, behavior = "auto", message_template, muffle = FALSE) http425(response, behavior = "auto", message_template, muffle = FALSE) http426(response, behavior = "auto", message_template, muffle = FALSE) http428(response, behavior = "auto", message_template, muffle = FALSE) http429(response, behavior = "auto", message_template, muffle = FALSE) http431(response, behavior = "auto", message_template, muffle = FALSE) http440(response, behavior = "auto", message_template, muffle = FALSE) http444(response, behavior = "auto", message_template, muffle = FALSE) http449(response, behavior = "auto", message_template, muffle = FALSE) http450(response, behavior = "auto", message_template, muffle = FALSE) http451(response, behavior = "auto", message_template, muffle = FALSE) http494(response, behavior = "auto", message_template, muffle = FALSE) http495(response, behavior = "auto", message_template, muffle = FALSE) http496(response, behavior = "auto", message_template, muffle = FALSE) http497(response, behavior = "auto", message_template, muffle = FALSE) http498(response, behavior = "auto", message_template, muffle = FALSE) http499(response, behavior = "auto", message_template, muffle = FALSE) http500(response, behavior = "auto", message_template, muffle = FALSE) http501(response, behavior = "auto", message_template, muffle = FALSE) http502(response, behavior = "auto", message_template, muffle = FALSE) http503(response, behavior = "auto", message_template, muffle = FALSE) http504(response, behavior = "auto", message_template, muffle = FALSE) http505(response, behavior = "auto", message_template, muffle = FALSE) http506(response, behavior = "auto", message_template, muffle = FALSE) http507(response, behavior = "auto", message_template, muffle = FALSE) http508(response, behavior = "auto", message_template, muffle = FALSE) http509(response, behavior = "auto", message_template, muffle = FALSE) http510(response, behavior = "auto", message_template, muffle = FALSE) http511(response, behavior = "auto", message_template, muffle = FALSE) http598(response, behavior = "auto", message_template, muffle = FALSE) http599(response, behavior = "auto", message_template, muffle = FALSE) http(response, behavior = "auto", message_template, muffle = FALSE)
http100(response, behavior = "auto", message_template, muffle = FALSE) http101(response, behavior = "auto", message_template, muffle = FALSE) http102(response, behavior = "auto", message_template, muffle = FALSE) http200(response, behavior = "auto", message_template, muffle = FALSE) http201(response, behavior = "auto", message_template, muffle = FALSE) http202(response, behavior = "auto", message_template, muffle = FALSE) http203(response, behavior = "auto", message_template, muffle = FALSE) http204(response, behavior = "auto", message_template, muffle = FALSE) http205(response, behavior = "auto", message_template, muffle = FALSE) http206(response, behavior = "auto", message_template, muffle = FALSE) http207(response, behavior = "auto", message_template, muffle = FALSE) http208(response, behavior = "auto", message_template, muffle = FALSE) http226(response, behavior = "auto", message_template, muffle = FALSE) http300(response, behavior = "auto", message_template, muffle = FALSE) http301(response, behavior = "auto", message_template, muffle = FALSE) http302(response, behavior = "auto", message_template, muffle = FALSE) http303(response, behavior = "auto", message_template, muffle = FALSE) http304(response, behavior = "auto", message_template, muffle = FALSE) http305(response, behavior = "auto", message_template, muffle = FALSE) http306(response, behavior = "auto", message_template, muffle = FALSE) http307(response, behavior = "auto", message_template, muffle = FALSE) http308(response, behavior = "auto", message_template, muffle = FALSE) http400(response, behavior = "auto", message_template, muffle = FALSE) http401(response, behavior = "auto", message_template, muffle = FALSE) http402(response, behavior = "auto", message_template, muffle = FALSE) http403(response, behavior = "auto", message_template, muffle = FALSE) http404(response, behavior = "auto", message_template, muffle = FALSE) http405(response, behavior = "auto", message_template, muffle = FALSE) http406(response, behavior = "auto", message_template, muffle = FALSE) http407(response, behavior = "auto", message_template, muffle = FALSE) http408(response, behavior = "auto", message_template, muffle = FALSE) http409(response, behavior = "auto", message_template, muffle = FALSE) http410(response, behavior = "auto", message_template, muffle = FALSE) http411(response, behavior = "auto", message_template, muffle = FALSE) http412(response, behavior = "auto", message_template, muffle = FALSE) http413(response, behavior = "auto", message_template, muffle = FALSE) http414(response, behavior = "auto", message_template, muffle = FALSE) http415(response, behavior = "auto", message_template, muffle = FALSE) http416(response, behavior = "auto", message_template, muffle = FALSE) http417(response, behavior = "auto", message_template, muffle = FALSE) http418(response, behavior = "auto", message_template, muffle = FALSE) http419(response, behavior = "auto", message_template, muffle = FALSE) http420(response, behavior = "auto", message_template, muffle = FALSE) http422(response, behavior = "auto", message_template, muffle = FALSE) http423(response, behavior = "auto", message_template, muffle = FALSE) http424(response, behavior = "auto", message_template, muffle = FALSE) http425(response, behavior = "auto", message_template, muffle = FALSE) http426(response, behavior = "auto", message_template, muffle = FALSE) http428(response, behavior = "auto", message_template, muffle = FALSE) http429(response, behavior = "auto", message_template, muffle = FALSE) http431(response, behavior = "auto", message_template, muffle = FALSE) http440(response, behavior = "auto", message_template, muffle = FALSE) http444(response, behavior = "auto", message_template, muffle = FALSE) http449(response, behavior = "auto", message_template, muffle = FALSE) http450(response, behavior = "auto", message_template, muffle = FALSE) http451(response, behavior = "auto", message_template, muffle = FALSE) http494(response, behavior = "auto", message_template, muffle = FALSE) http495(response, behavior = "auto", message_template, muffle = FALSE) http496(response, behavior = "auto", message_template, muffle = FALSE) http497(response, behavior = "auto", message_template, muffle = FALSE) http498(response, behavior = "auto", message_template, muffle = FALSE) http499(response, behavior = "auto", message_template, muffle = FALSE) http500(response, behavior = "auto", message_template, muffle = FALSE) http501(response, behavior = "auto", message_template, muffle = FALSE) http502(response, behavior = "auto", message_template, muffle = FALSE) http503(response, behavior = "auto", message_template, muffle = FALSE) http504(response, behavior = "auto", message_template, muffle = FALSE) http505(response, behavior = "auto", message_template, muffle = FALSE) http506(response, behavior = "auto", message_template, muffle = FALSE) http507(response, behavior = "auto", message_template, muffle = FALSE) http508(response, behavior = "auto", message_template, muffle = FALSE) http509(response, behavior = "auto", message_template, muffle = FALSE) http510(response, behavior = "auto", message_template, muffle = FALSE) http511(response, behavior = "auto", message_template, muffle = FALSE) http598(response, behavior = "auto", message_template, muffle = FALSE) http599(response, behavior = "auto", message_template, muffle = FALSE) http(response, behavior = "auto", message_template, muffle = FALSE)
response |
The result of a call via crul, curl, or httr |
behavior |
Behavior of the error. default: auto. See Details |
message_template |
A message template. optional. use whisker
templating. names to use are: reason and status. use in template
like |
muffle |
(logical) whether to not respond when status codes
in 1xx-3xx series. Default: |
stop - use stop
warning - use warning
message - use message
auto - toggle between stop
and message
depending
on the HTTP status code series. Defaults will be:
1xx: message
2xx: message
3xx: message
4xx: stop
5xx: stop
Of course, you can always override the defaults.
curl reponses are simple lists, so we have little to go on to make sure it's a response from the curl package. We check for list names internally but of course you could pass in a list with the right named elements, while the values are complete nonsense, in which case we'll probably fail badly. There's not much we can do.
These http*
methods only use $do
and not
$do_verbose
.
res <- list(url="https://a.com", status_code=200, type="application/xml", headers=charToRaw("a"), modified=NA, times=5, content=charToRaw('b')) http(res, behavior = "message")
res <- list(url="https://a.com", status_code=200, type="application/xml", headers=charToRaw("a"), modified=NA, times=5, content=charToRaw('b')) http(res, behavior = "message")