cubicweb/web/views/ajaxcontroller.py
changeset 12187 3a1f742b84cd
parent 11767 432f87a63057
child 12188 fea018b2e056
--- a/cubicweb/web/views/ajaxcontroller.py	Fri Apr 28 09:49:37 2017 +0200
+++ b/cubicweb/web/views/ajaxcontroller.py	Mon Jun 19 18:00:26 2017 +0200
@@ -133,6 +133,7 @@
             warn('[3.15] remote function %s found on JSonController, '
                  'use AjaxFunction / @ajaxfunc instead' % fname,
                  DeprecationWarning, stacklevel=2)
+        debug_mode = self._cw.vreg.config.debugmode
         # no <arg> attribute means the callback takes no argument
         args = self._cw.form.get('arg', ())
         if not isinstance(args, (list, tuple)):
@@ -140,16 +141,19 @@
         try:
             args = [json.loads(arg) for arg in args]
         except ValueError as exc:
-            self.exception('error while decoding json arguments for '
-                           'js_%s: %s (err: %s)', fname, args, exc)
+            if debug_mode:
+                self.exception('error while decoding json arguments for '
+                               'js_%s: %s (err: %s)', fname, args, exc)
             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
         try:
             result = func(*args)
         except (RemoteCallFailed, DirectResponse):
             raise
         except Exception as exc:
-            self.exception('an exception occurred while calling js_%s(%s): %s',
-                           fname, args, exc)
+            if debug_mode:
+                self.exception(
+                    'an exception occurred while calling js_%s(%s): %s',
+                    fname, args, exc)
             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
         if result is None:
             return ''
@@ -219,7 +223,8 @@
         try:
             return self._cw.execute(rql, args)
         except Exception as ex:
-            self.exception("error in _exec(rql=%s): %s", rql, ex)
+            if self._cw.vreg.config.debugmode:
+                self.exception("error in _exec(rql=%s): %s", rql, ex)
             return None
         return None