ApiErrorResponse - viames/pair GitHub Wiki
Pair framework: ApiErrorResponse
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().
Constructor
new ApiErrorResponse(string $errorCode, string $errorMessage, int $httpCode = 400, array $extra = [])
Arguments:
errorCode: stable machine-readable codeerrorMessage: human-readable error messagehttpCode: HTTP status codeextra: 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"
}
Notes
- 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.