WooCommerce Code Reference

ValidationException extends ApiException
in package

Thrown to signal that input is well-formed but failed business-rule validation, e.g. a required field was empty, two fields contradict each other, a value violates a domain constraint.

For purely structural input errors (wrong type, malformed shape) prefer letting the framework's \InvalidArgumentException handling do the work: Utils::translate_exceptions() already maps it to INVALID_ARGUMENT (400).

Wire shape: extensions.code = 'VALIDATION_ERROR', HTTP status 422.

Table of Contents

__construct()  : mixed
Constructor.
getErrorCode()  : string
Get the machine-readable error code.
getExtensions()  : array<string|int, mixed>
Get the additional error metadata.
getStatusCode()  : int
Get the HTTP status code.

Methods

__construct()

Constructor.

public __construct([string $message = 'Validation failed.' ][, array<string|int, mixed> $extensions = array() ][, Throwable|null $previous = null ]) : mixed
Parameters
$message : string = 'Validation failed.'

The error message.

$extensions : array<string|int, mixed> = array()

Additional error metadata to surface in the GraphQL extensions object.

$previous : Throwable|null = null

The previous throwable for chaining.

Return values
mixed

getErrorCode()

Get the machine-readable error code.

public getErrorCode() : string
Return values
string

getExtensions()

Get the additional error metadata.

public getExtensions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getStatusCode()

Get the HTTP status code.

public getStatusCode() : int
Return values
int