WC_Helper::record_api_error
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.
Method of the class: WC_Helper{}
No Hooks.
Returns
void. Nothing (null).
Usage
$result = WC_Helper::record_api_error( $code, $message ): void;
- $code(int) (required)
- HTTP status code, or 0 for a transport-level failure.
- $message(string) (required)
- Fallback message for failures with no HTTP status.
WC_Helper::record_api_error() WC Helper::record api error code WC 11.2.1
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
);
}