Description Arguments Details behavior parameter options See Also Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | Error$new()
# reset behavior
(z <- Error$new())
z$set_behavior("warning")
z
if (requireNamespace("crul")) {
library("crul")
res <- HttpClient$new("https://httpbin.org/status/418")$get()
# stop
(x <- Error$new(behavior = "stop"))
## Not run: x$do(res)
# warn
(x <- Error$new(behavior = "warning"))
x$do(res)
# do vs. do_verbose
x <- HTTPRequestURITooLong$new(behavior = "stop")
res <- HttpClient$new("https://httpbin.org/status/414")$get()
## Not run:
http414(res)
## with template
http414(res, message_template = "{{status}}\n --> {{reason}}")
x$do(res)
x$do_verbose(res)
## End(Not run)
# service unavailable
x <- HTTPServiceUnavailable$new(behavior = "stop")
res <- HttpClient$new("https://httpbin.org/status/503")$get()
## Not run:
x$do(res)
x$do_verbose(res)
## End(Not run)
# message template
y <- Error$new(message_template = "{{reason}} ............ {{status}}")
res <- HttpClient$new("https://httpbin.org/status/418")$get()
## Not run:
y$do(res)
## End(Not run)
yy <- Error$new(message_template = "{{status}}\n --> {{reason}}")
yy$message_template
## Not run:
yy$do(res)
## End(Not run)
## with verbose message
library(crul)
res <- HttpClient$new("https://httpbin.org/status/401")$get()
yy <- HTTPUnauthorized$new()
zz <- HTTPUnauthorized$new(
message_template = "HTTP({{status}}): {{reason}}\n {{message}}"
)
yy$message_template; zz$message_template
## Not run:
yy$do(res)
zz$do(res)
yy$do_verbose(res)
zz$do_verbose(res)
## End(Not run)
yy <- Error$new(
message_template = "HTTP({{status}}): {{reason}}\n {{message}}"
)
yy$message_template
## Not run: yy$do(res)
# muffle responses
(x <- Error$new(muffle = TRUE))
res <- crul::HttpClient$new("https://httpbin.org/status/226")$get()
z <- x$do(res)
z
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.