API / Minn / RestError

RestError final class

Minn\RestError · public/minn/src/Minn/RestError.php · 60 lines · implements Stringable, Throwable · extends RuntimeException

A WordPress-shaped error, thrown from anywhere and rendered once by the kernel: {"code": ..., "message": ..., "data": {"status": ...}}.

Constants and properties

propreadonly string $errorCode

Promoted from the constructor.

propreadonly int $status

Promoted from the constructor.

propreadonly array $extra

Promoted from the constructor.

propreadonly array $topLevel

Promoted from the constructor.

privatereadonly bool $bare

Promoted from the constructor.

Public

new__construct(string $errorCode, string $message, int $status, array $extra = array ( ), array $topLevel = array ( ), bool $bare = false)#
$extraarray<string, mixed>keys added beside status inside data (the whole of data when it names status)
$topLevelarray<string, mixed>keys added beside code/message/data
staticnoRoute(): self#

The reference's 404 for a route nothing answers.

staticmissingParams(array $params): self#

The reference's 400 for required parameters that did not arrive.

$paramslist<string>
staticinvalidParam(string $param, string $message, string $code = 'rest_not_in_enum', mixed $data = NULL): self#

The reference's 400 for one parameter its schema refuses: the message under params, and under details with the refusal's code and data, as WP_REST_Request::has_valid_params reports it.

staticbare(string $code, string $message): self#

A statusless core error as REST serves it: HTTP 500 with data null.

methodpayload(): array#

The error as the reference's JSON body: code, message, data.