WC_Helper::record_api_error │ private static │ WC 1.0

Record the last failed Helper API subscriptions response.

The message is stored alongside the code because it is often more specific than anything we can rebuild from the status alone — a 401 carries reconnect guidance, a 422 explains an unparseable body. Where we do have purpose-written copy for a status, get_api_error() rebuilds it on read so it lands in the viewer's locale instead of the recording request's.

A 429 is held for the whole backoff window, otherwise the notice would disappear while requests are still being suppressed and the screen would silently revert to looking like an empty account.

Метод класса: WC_Helper{}

Хуков нет.

Возвращает

void. Ничего (null).

Использование

$result = WC_Helper::record_api_error( $code, $message ): void;
$code(int) (обязательный)
HTTP status code, or 0 for a transport-level failure.
$message(строка) (обязательный)
Fallback message for failures with no HTTP status.

Код WC_Helper::record_api_error() WC 11.3.0

private static function record_api_error( int $code, string $message ): void {
	if ( $code < 100 ) {
		// get_api_error() replaces this with merchant-facing guidance, and the
		// catch in get_subscriptions() only logs failures from 404 up, so
		// without this the transport detail would be lost entirely.
		self::log( 'Could not reach the WooCommerce.com API: ' . $message, 'error' );
	}

	$ttl = 15 * MINUTE_IN_SECONDS;

	if ( 429 === $code ) {
		$retry_after = WC_Helper_API_Backoff::get_retry_after( WC_Helper_API_Backoff::REQUEST_TYPE_SUBSCRIPTIONS );

		if ( null !== $retry_after ) {
			$ttl = $retry_after;
		}
	}

	set_transient(
		self::CACHE_KEY_API_ERROR,
		array(
			'code'    => $code,
			'message' => $message,
		),
		$ttl
	);
}