Skip to contents

Handle http request errors

Usage

vcr_last_error()

Details

How this error class is used: If record="once" we trigger this.

Users can use vcr in the context of both use_cassette() and insert_cassette()

For the former, all requests go through the call_block But for the latter, requests go through webmockr.

Where is one place where we can put UnhandledHTTPRequestError that will handle both use_cassette and insert_cassette?

Error situations where this is invoked

  • record=once AND there's a new request that doesn't match the one in the cassette on disk

    • in webmockr: if no stub found and there are recorded interactions on the cassette, and record = once, then error with UnhandledHTTPRequestError

      • but if record != once, then allow it, unless record == none

  • others?

Public fields

request

a Request object

cassette

a cassette name

Methods


Method new()

Create a new UnhandledHTTPRequestError object

Usage

Arguments

request

(Request) a Request object

Returns

A new UnhandledHTTPRequestError object


Method run()

Run unhandled request handling

Usage

UnhandledHTTPRequestError$run()

Returns

various


Method construct_message()

Construct and execute stop message for why request failed

Usage

UnhandledHTTPRequestError$construct_message()

Returns

a stop message


Method request_description()

construct request description

Usage

UnhandledHTTPRequestError$request_description()

Returns

character


Method current_matchers()

get current request matchers

Usage

UnhandledHTTPRequestError$current_matchers()

Returns

character


Method match_request_on_headers()

are headers included in current matchers?

Usage

UnhandledHTTPRequestError$match_request_on_headers()

Returns

logical


Method match_request_on_body()

is body includled in current matchers?

Usage

UnhandledHTTPRequestError$match_request_on_body()

Returns

logical


Method formatted_headers()

get request headers

Usage

UnhandledHTTPRequestError$formatted_headers()

Returns

character


Method cassettes_description()

construct description of current or lack thereof cassettes

Usage

UnhandledHTTPRequestError$cassettes_description()

Returns

character


Method cassettes_list()

cassette details

Usage

UnhandledHTTPRequestError$cassettes_list()

Returns

character


Method get_help()

get help message for non-verbose error

Usage

UnhandledHTTPRequestError$get_help()

Returns

character


Method formatted_suggestions()

make suggestions for what to do

Usage

UnhandledHTTPRequestError$formatted_suggestions()

Returns

character


Method format_bullet_point()

add bullet point to beginning of a line

Usage

UnhandledHTTPRequestError$format_bullet_point(lines, index)

Arguments

lines

(character) vector of strings

index

(integer) a number

Returns

character


Method format_foot_note()

make a foot note

Usage

UnhandledHTTPRequestError$format_foot_note(url, index)

Arguments

url

(character) a url

index

(integer) a number

Returns

character


Method suggestion_for()

get a suggestion by key

Usage

UnhandledHTTPRequestError$suggestion_for(key)

Arguments

key

(character) a character string

Returns

character


Method suggestions()

get all suggestions

Usage

UnhandledHTTPRequestError$suggestions()

Returns

list


Method no_cassette_suggestions()

get all no cassette suggestions

Usage

UnhandledHTTPRequestError$no_cassette_suggestions()

Returns

list


Method record_mode_suggestion()

get the appropriate record mode suggestion

Usage

UnhandledHTTPRequestError$record_mode_suggestion()

Returns

character


Method has_used_interaction_matching()

are there any used interactions

Usage

UnhandledHTTPRequestError$has_used_interaction_matching()

Returns

logical


Method match_requests_on_suggestion()

match requests on suggestion

Usage

UnhandledHTTPRequestError$match_requests_on_suggestion()

Returns

list


Method clone()

The objects of this class are cloneable with this method.

Usage

UnhandledHTTPRequestError$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) { # \dontrun{
vcr_configure(dir = tempdir())
cassettes()
insert_cassette("turtle")
request <- Request$new("post", 'https://hb.opencpu.org/post?a=5',
  "", list(foo = "bar"))

err <- UnhandledHTTPRequestError$new(request)
err$request_description()
err$current_matchers()
err$match_request_on_headers()
err$match_request_on_body()
err$formatted_headers()
cat(err$formatted_headers(), "\n")
cat(err$cassettes_description(), "\n")
cat(err$cassettes_list(), "\n")
err$formatted_suggestions()
cat(err$format_bullet_point('foo bar', 1), "\n")
err$suggestion_for("use_new_episodes")
err$suggestions()
err$no_cassette_suggestions()
err$record_mode_suggestion()
err$has_used_interaction_matching()
err$match_requests_on_suggestion()

# err$construct_message()

# cleanup
eject_cassette("turtle")
unlink(tempdir())
} # }
if (FALSE) { # \dontrun{
# vcr_last_error()
} # }