Closed mtymek closed 10 years ago
@mtymek First, please ask questions on the mailing list, not the issue trackers.
Second, as of 2 weeks ago, we released 0.8.0 of Apigility, which includes and integrates a new module, zf-content-validation, which allows you to create input filters that you attach to specific services; if data passed to the service does not validate, it will return an API-Problem response with validation error messages.
Third, if you want to report errors yourself, there are a couple ways to do this.
Create and return an ZF\ApiProblem\ApiProblem
instance. This allows you to set all details you want, including custom status code and validation messages. As an example:
return new \ZF\ApiProblem\ApiProblem(409, 'Invalid data', null, null, [
'messages' => $filter->getMessages(),
]);
Alternately, use and throw an implementation of ZF\ApiProblem\Exception\ProblemExceptionInterface
, such as ZF\ApiProblem\Exception\DomainException
. This exception type allows you to set the additional details you want to provide in the problem response:
$ex = new \ZF\ApiProblem\Exception\DomainException('Invalid data!', 409);
$ex->setAdditionalDetails(['messages' => $filter->getMessages()]);
throw $ex;
@danizord Those docs are out-of-date, and from PhlyRestfully. Thanks for the reminder that I need to remove them!
@weierophinney Sorry, I got confused with the module names. Going to remove my comment.
Allright, thanks for the tips!
I'm playing around with
zf-rest
and other modules related to Apigility (great work BTW!). I'm currently stuck when trying to report detailed errors from REST resource. I want to use InputFilter to validate an entity, then report back exactly which fields were filled incorrectly.Take a look at my current code:
Now, instead of throwing an exception when something is wrong, I'd like to somehow return all messages from input filter. Is there any standard way to do that? Or should I just "invent" my own format, like this: