-
Notifications
You must be signed in to change notification settings - Fork 85
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior
Description
Hello,
I try to use req_error() for handing next respons:
<httr2_response>
GET https://api.tgstat.ru/usage/stat?token=asdfghjklkjhgfd
Status: 200 OK
Content-Type: application/json
Body: In memory (42 bytes)
resp_body_json(resp)
$status
[1] "error"
$error
[1] "token_invalid"
And i try use
tg_error_body <- function(resp) {
resp %>% resp_body_json() %>% .$error
}
tg_is_error <- function(resp) {
resp_stat <- resp %>% resp_body_json() %>% .$status
resp_status(resp) == 200 && resp_stat == "error"
}
resp <- request(str_glue('{getOption("tg.base_url")}')) %>%
req_url_path_append(method) %>%
req_url_query( token = 'False access token') %>%
req_user_agent("rtgstat") %>%
req_retry(
max_tries = getOption('tg.max_tries'),
is_transient = ~ !is_response(.x) && resp_status(.x) != 200,
after = getOption('tg.interval')
) %>%
req_error(is_error = function(resp) TRUE, body = tg_error_body) %>%
req_perform() %>%
resp_body_json()And it does not work, could you help, how i can handing error response with status 200?
minimal reprex
request("http://httpbin.org/") %>%
req_error(is_error = function(resp) TRUE) %>%
req_perform()
<httr2_response>
GET http://httpbin.org/
Status: 200 OK
Content-Type: text/html
Body: In memory (9593 bytes)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior