-
Notifications
You must be signed in to change notification settings - Fork 2
ApiErrorResponse
Viames Marino edited this page Apr 20, 2026
·
1 revision
Pair\Api\ApiErrorResponse is the explicit response object for standardized API errors.
Use it when you want to return a ResponseInterface instance instead of terminating the request immediately through ApiResponse::error().
new ApiErrorResponse(string $errorCode, string $errorMessage, int $httpCode = 400, array $extra = [])
Arguments:
-
errorCode: stable machine-readable code -
errorMessage: human-readable error message -
httpCode: HTTP status code -
extra: additional payload fields merged into the JSON body
Example:
use Pair\Api\ApiErrorResponse;
return new ApiErrorResponse('BAD_REQUEST', 'Invalid payload', 422, [
'detail' => 'Missing field',
]);Emitted payload:
{
"code": "BAD_REQUEST",
"error": "Invalid payload",
"detail": "Missing field"
}- Non-string keys in
$extraare ignored. -
send()delegates to the JSON response path, so the runtime behavior stays aligned with other explicit Pair v4 responses. - If you want to reuse the built-in/custom
ApiResponseerror registry, preferApiResponse::errorResponse().
See also: ApiResponse, API, Request.