Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# httr2 (development version)

* `last_response_json()` now works with content-types that end with `+json`,
e.g., `application/problem+json` (@cgiachalis, #782).

# httr2 1.2.2

* httr2 will now emit OpenTelemetry traces for all requests when tracing is enabled. Requires the `otelsdk` package (@atheriel, #729).
Expand Down
9 changes: 6 additions & 3 deletions R/last.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ last_response_json <- function(pretty = TRUE) {
if (is.null(resp)) {
cli::cli_abort("No request has been made successfully yet.")
}
if (!identical(resp_content_type(resp), "application/json")) {
cli::cli_abort("Last response doesn't have a JSON body.")
}
check_content_type(
resp_content_type(resp),
valid_types = "application/json",
valid_suffix = "json",
inform_check_type = TRUE
)
httr2_json(resp_body_string(resp), pretty = pretty)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/_snaps/last.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
last_response_json()
Condition
Error in `last_response_json()`:
! Last response doesn't have a JSON body.
! Unexpected content type "application/xml".
* Expecting type "application/json" or suffix "json".

# useful errors if no last request/response

Expand Down