WooCommerce Code Reference

Error
in package

Error class.

Represents an error object as defined in the Agentic Commerce Protocol. This class handles API-level errors with type, code, message, and optional param.

Table of Contents

$code  : string
Implementation-defined error code.
$message  : string
Human-readable error message.
$param  : string|null
RFC 9535 JSONPath to the problematic parameter (optional).
$type  : string
The error type.
invalid_request()  : Error
Create an invalid request error.
processing_error()  : Error
Create a processing error.
request_not_idempotent()  : Error
Create a request not idempotent error.
service_unavailable()  : Error
Create a service unavailable error.
to_rest_response()  : WP_REST_Response
Convert the error to a WP_REST_Response.
__construct()  : mixed
Constructor.
get_http_status_code()  : int
Determine HTTP status code based on error type.

Properties

Methods

invalid_request()

Create an invalid request error.

public static invalid_request(string $code, string $message[, string|null $param = null ]) : Error
Parameters
$code : string

Implementation-defined error code.

$message : string

Human-readable error message.

$param : string|null = null

RFC 9535 JSONPath (optional).

Return values
Error

processing_error()

Create a processing error.

public static processing_error(string $code, string $message[, string|null $param = null ]) : Error
Parameters
$code : string

Implementation-defined error code.

$message : string

Human-readable error message.

$param : string|null = null

RFC 9535 JSONPath (optional).

Return values
Error

request_not_idempotent()

Create a request not idempotent error.

public static request_not_idempotent(string $code, string $message[, string|null $param = null ]) : Error
Parameters
$code : string

Implementation-defined error code.

$message : string

Human-readable error message.

$param : string|null = null

RFC 9535 JSONPath (optional).

Return values
Error

service_unavailable()

Create a service unavailable error.

public static service_unavailable(string $code, string $message[, string|null $param = null ]) : Error
Parameters
$code : string

Implementation-defined error code.

$message : string

Human-readable error message.

$param : string|null = null

RFC 9535 JSONPath (optional).

Return values
Error

to_rest_response()

Convert the error to a WP_REST_Response.

public to_rest_response() : WP_REST_Response
Return values
WP_REST_ResponseWordPress REST API response object

__construct()

Constructor.

private __construct(string $type, string $code, string $message[, string|null $param = null ]) : mixed
Parameters
$type : string

Error type from ErrorType enum.

$code : string

Implementation-defined error code.

$message : string

Human-readable error message.

$param : string|null = null

RFC 9535 JSONPath (optional).

Return values
mixed