[views] Respond with 400 Bad Request in case of validation error in ajax request
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 12 Sep 2017 15:05:22 +0200
changeset 12208 159dce89a145
parent 12206 cfd25da225c2
child 12209 3a3551fff787
[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.
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(