response_process() is intended primarily for internal use in client packages that provide high-level wrappers for users. Typically applied as the final step in this sequence of calls:

All that's needed for a successful request is to parse the JSON extracted via httr::content(). Therefore, the main point of response_process() is to handle less happy outcomes:

  • Status codes in the 400s (client error) and 500s (server error). The structure of the error payload varies across Google APIs and we try to create a useful message for all variants we know about.

  • Non-JSON content type, such as HTML.

  • Status code in the 100s (information) or 300s (redirection). These are unexpected.

response_process(resp, error_message = gargle_error_message)





Object of class response from httr.


Function that produces an informative error message from the primary input, resp. It must return a character vector.


The content of the request, as a list. An HTTP status code of 204 (No content) is a special case returning TRUE.


If process_response() results in an error, a redacted version of the resp input is returned in the condition (auth tokens are removed). Use functions such as rlang::last_error() or rlang::catch_cnd() to capture the condition and do a more detailed forensic examination.

The response_as_json() helper is exported only as an aid to maintainers who wish to use their own error_message function, instead of gargle's built-in gargle_error_message(). When implementing a custom error_message function, call response_as_json() immediately on the input in order to inherit gargle's handling of non-JSON input.

See also

Other requests and responses: request_develop, request_make


# get an OAuth2 token with '' scope
token <- token_fetch(scopes = "")

# see the email associated with this token
req <- gargle::request_build(
  method = "GET",
  path = "v1/userinfo",
  token = token,
  base_url = ""
resp <- gargle::request_make(req)

# make a bad request (this token has incorrect scope)
req <- gargle::request_build(
  method = "GET",
  path = "fitness/v1/users/{userId}/dataSources",
  token = token,
  params = list(userId = 12345)
resp <- gargle::request_make(req)
# }