# HG changeset patch # User Denis Laxalde # Date 1505221522 -7200 # Node ID 159dce89a145f742ce05d993474e3f125878a8e8 # Parent cfd25da225c2590b35bfe1a4d8c920a9356633e3 [views] Respond with 400 Bad Request in case of validation error in ajax request Previously, we raised a plain RemoteCallFailed without a status code, in which case it defaults to "500 Internal Server Error". Now, for validation errors, we issue a 400 Bad Request since these are clearly client errors. diff -r cfd25da225c2 -r 159dce89a145 cubicweb/web/views/ajaxcontroller.py --- a/cubicweb/web/views/ajaxcontroller.py Fri Oct 06 16:59:10 2017 +0200 +++ b/cubicweb/web/views/ajaxcontroller.py Tue Sep 12 15:05:22 2017 +0200 @@ -73,7 +73,7 @@ from logilab.common.registry import yes from logilab.common.deprecation import deprecated -from cubicweb import ObjectNotFound, NoSelectableObject +from cubicweb import ObjectNotFound, NoSelectableObject, ValidationError from cubicweb.appobject import AppObject from cubicweb.utils import json, json_dumps, UStringIO from cubicweb.uilib import exc_message @@ -153,6 +153,9 @@ result = func(*args) except (RemoteCallFailed, DirectResponse): raise + except ValidationError: + raise RemoteCallFailed(exc_message(exc, self._cw.encoding), + status=http_client.BAD_REQUEST) except Exception as exc: if debug_mode: self.exception(