API uses ApiProblem and ApiProblemResponse for structured failures.
The response content type is:
application/problem+json; charset=utf-8
use CommonPHP\API\ApiProblem;
use CommonPHP\HTTP\Enums\ResponseStatus;
$problem = ApiProblem::forStatus(
ResponseStatus::CONFLICT,
'The resource already exists.',
code: 'resource_conflict',
);The JSON body includes type, title, and status. It includes detail, instance, code, errors, and extension fields when supplied.
$problem = ApiProblem::fromValidation($result);Validation problems use:
- status
422; - title
Validation Failed; - code
validation_failed; - an
errorsarray based onValidationResult::toArray().
Use extension fields for safe, client-useful metadata:
$problem = ApiProblem::forStatus(429, 'Too many requests.')
->withExtension('retry_after_seconds', 30);Reserved fields such as title and status are not overwritten by extensions.
Generic server exceptions should usually omit internal details. ApiExceptionHandler hides generic throwable details by default. Pass exposeDetails: true only in controlled development or test environments.