I personally used this thing here, which I like better because it
doesn't introduce yet another decorator:
@expose("json")
def json_error_handler(self, *unused_args, **unused_kwargs):
"""
Error-handler to be used in json-methods.
This error-handler will set the respons-status to
412 (Precodition Failed)
and returns a mapping of parameter-names to their
error-messages.
"""
response.status = 412
return c.form_errors
You use it on a controller as error_handler in the @validate-decorator.
And I personally think that using HTTP-response-codes is better
protocol-wise, as you don't pollute your returned objects namespace, but
instead can use a simple error-handler on the AJAX-side.
Diez