From aa6e81e8e3e88d4034ace26005dc6f6973788d5a Mon Sep 17 00:00:00 2001 From: Constantinos Giachalis Date: Wed, 14 Jan 2026 11:20:36 +0200 Subject: [PATCH 1/4] 'application/problem+json' works with `last_response_json()` closes #782 --- R/last.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/last.R b/R/last.R index 625d5d01..15f317f7 100644 --- a/R/last.R +++ b/R/last.R @@ -61,7 +61,9 @@ 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")) { + content_type <- resp_content_type(resp) + if (!(identical(content_type, "application/json") || + identical(content_type, "application/problem+json"))) { cli::cli_abort("Last response doesn't have a JSON body.") } httr2_json(resp_body_string(resp), pretty = pretty) From eba268526c1dc20f4b94668c90542febb5f09f4c Mon Sep 17 00:00:00 2001 From: Constantinos Giachalis Date: Wed, 14 Jan 2026 19:19:14 +0200 Subject: [PATCH 2/4] code review: use `check_content_type()` --- R/last.R | 11 ++++++----- tests/testthat/_snaps/last.md | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/last.R b/R/last.R index 15f317f7..c57beb14 100644 --- a/R/last.R +++ b/R/last.R @@ -61,11 +61,12 @@ last_response_json <- function(pretty = TRUE) { if (is.null(resp)) { cli::cli_abort("No request has been made successfully yet.") } - content_type <- resp_content_type(resp) - if (!(identical(content_type, "application/json") || - identical(content_type, "application/problem+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) } diff --git a/tests/testthat/_snaps/last.md b/tests/testthat/_snaps/last.md index a8da3918..90957b31 100644 --- a/tests/testthat/_snaps/last.md +++ b/tests/testthat/_snaps/last.md @@ -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 From f80bfc32cba22d395cef25d593c07c0ba0f581d8 Mon Sep 17 00:00:00 2001 From: Constantinos Giachalis Date: Wed, 14 Jan 2026 20:00:10 +0200 Subject: [PATCH 3/4] Update NEWS.md --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index e2e85e4c..21423082 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # httr2 (development version) +## Minor improvements and bug fixes + +* `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). From a7ab6dabda46056c4e9b5434bca9bc1041f305e9 Mon Sep 17 00:00:00 2001 From: Constantinos Giachalis Date: Wed, 14 Jan 2026 21:04:18 +0200 Subject: [PATCH 4/4] remove heading [ci skip] --- NEWS.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 21423082..db15ae62 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,5 @@ # httr2 (development version) -## Minor improvements and bug fixes - * `last_response_json()` now works with content-types that end with `+json`, e.g., `application/problem+json` (@cgiachalis, #782).