Error: Error class

Description Arguments Details behavior parameter options See Also Examples

Description

Error class

Arguments

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 {{reason}} and {{status}}. Note that {{message}} that is used in message_template_verbose will be ignored here.

call.

(logical) indicating if the call should become part of the error message. Default: FALSE

message_template_verbose

A verbose message template. optional. use whisker templating. names to use are: reason, status, message. use in template like {{reason}}, {{status}}, and {{message}}. Note that this is ignored here, but is used in the HTTP* methods (e.g. HTTPBadRequest)

muffle

(logical) whether to not respond when status codes in 1xx-3xx series. Default: FALSE

Details

Methods

behavior parameter options

Of course, you can always override the defaults.

See Also

http, Error-Classes

Examples

 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
}

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