check_for_failed_request: Check for failed API request

View source: R/check_for_failed_request.R

check_for_failed_requestR Documentation

Check for failed API request

Description

This function checks the response body from an API request to determine if the request failed. If the request contains an error message, the function will raise an error with a detailed message including the message ID and value.

Usage

check_for_failed_request(body)

Arguments

body

The response body from the API request, typically in JSON format, which may contain an error message if the request failed.

Details

This function inspects the first element of the response body to check for an error message. If a message is found, the function retrieves the id, key, and value fields from the error message and constructs an error using cli::cli_abort(). The function is intended to ensure failed API requests are handled gracefully.

Value

This function does not return a value. If the request contains an error message, it raises an error and halts execution.


wdi2 documentation built on Sept. 13, 2024, 1:12 a.m.