[bwcompat] Make the error handler optional
authorChristophe de Vienne <christophe@unlish.com>
Fri, 24 Jul 2015 14:21:13 +0200
changeset 11588 50e1fda83837
parent 11587 18dd303225cd
child 11589 7079ba70c2a7
[bwcompat] Make the error handler optional Closes #5739625
docs/narr/settings.rst
pyramid_cubicweb/bwcompat.py
--- a/docs/narr/settings.rst	Mon Jul 06 14:51:06 2015 +0200
+++ b/docs/narr/settings.rst	Fri Jul 24 14:21:13 2015 +0200
@@ -92,6 +92,11 @@
 
     (True) Enable/disable backward compatibility. See :ref:`bwcompat_module`.
 
+.. confval:: cubicweb.bwcompat.errorhandler (bool)
+
+    (True) Enable/disable the backward compatibility error handler.
+    Set to 'no' if you need to define your own error handlers.
+
 .. confval:: cubicweb.defaults (bool)
 
     (True) Enable/disable defaults. See :ref:`defaults_module`.
--- a/pyramid_cubicweb/bwcompat.py	Mon Jul 06 14:51:06 2015 +0200
+++ b/pyramid_cubicweb/bwcompat.py	Fri Jul 24 14:21:13 2015 +0200
@@ -4,6 +4,7 @@
 from pyramid import tweens
 from pyramid.httpexceptions import HTTPSeeOther
 from pyramid import httpexceptions
+from pyramid.settings import asbool
 
 import cubicweb
 import cubicweb.web
@@ -196,6 +197,8 @@
 
     config.add_tween(
         'pyramid_cubicweb.bwcompat.TweenHandler', under=tweens.EXCVIEW)
-    config.add_view(cwhandler.error_handler, context=Exception)
-    # XXX why do i need this?
-    config.add_view(cwhandler.error_handler, context=httpexceptions.HTTPForbidden)
+    if asbool(config.registry.settings.get(
+            'cubicweb.bwcompat.errorhandler', True)):
+        config.add_view(cwhandler.error_handler, context=Exception)
+        # XXX why do i need this?
+        config.add_view(cwhandler.error_handler, context=httpexceptions.HTTPForbidden)