Wednesday, March 12, 2014

Re: RESTful (Form) Validation?

Thanks, AD. I'll be reading the example today.

Cheers,
OJ

On Wednesday, March 12, 2014 12:06:00 PM UTC+8, OJ Tibi - @ojtibi wrote:
Hi folks,

I was wondering if there was a way to let the client app know which fields it submitted have validation errors. (As you can see, I placed "Form" between parentheses because there isn't really an HTML form in a REST API request.) While the Cookbook recommends to use the built-in Exception classes to respond to errors in REST requests, there is no recommended way to include Model::validationErrors in the response.

Right now, I'm inclined to create my own subclass of HttpException, but after reading the core files, it looks like I might also need to create a custom ErrorHandler and ExceptionRenderer class, if I understand correctly. Essentially, I just want to add a 'validation_errors' key in the '_serialize' array exported by ExceptionRenderer.

The question is, will I be overdoing it if I did what I outlined above, *or* should I just pass a implode()'d Model::validationErrors as a $message to BadRequestException/InternalErrorException? Also note that Model::validationErrors is a multi-level array with named keys.

Cheers,
OJ

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: