# HG changeset patch # User Denis Laxalde # Date 1497888026 -7200 # Node ID 3a1f742b84cd7d93e68788cb5f5a17a2f7831bef # Parent af5d0a3c3f1aed458341ac167d8be1cc58b4404b [web] Only log exceptions in debug mode in Ajax controllers When we raise a RemoteCallFailed error (erroneously turned into a '500 Internal Server Error' response, but that's another business). In production environment, we do not want to log the exception in most cases where it's actually a client error. So only log the exception in debug mode. diff -r af5d0a3c3f1a -r 3a1f742b84cd cubicweb/web/views/ajaxcontroller.py --- 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 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