RestException

Class. It extends RuntimeException.

use Saij\WpAppFramework\Rest\RestException;

Ends a REST request with an error response: thrown from a route or permission method, it becomes a WP_Error with the given code and HTTP status.

Constructor

new RestException(string $errorCode, string $message, int $status, array $data = [], ?Throwable $previous = null)
ParameterTypeDefaultDescription
errorCodestringrequiredMachine-readable error code, e.g. sections_item_not_found.
messagestringrequiredThe error message for the client, readable by humans.
statusintrequiredHTTP status, 400–599.
dataarray<string, mixed>[]Additional error data; status is always the given status.
previousThrowable|nullnullThe exception that caused this one, if any.

Methods

getData()

getData(): array

The additional error data as given to the constructor; in the response, status is always the status of the exception.

Returns array<string, mixed>

getErrorCode()

getErrorCode(): string

The machine-readable error code of the response.

Returns string

getStatus()

getStatus(): int

The HTTP status of the response, 400 to 599.

Returns int